1

I managed to configure my Apache to run cgi scripts and I tried to use javascript to generate output.

#!C:\php\php.exe

<script>
  document.write("Hello world!");
</script>

However this only sends the contents and the document.write is run on the client. I'd like to send Hello world! by javascript.

I know there is nodejs. I wonder if there is a module for Apache or some settings that enables running javascript on the server and send only the contents of document.write?

1 Answer 1

1

CGI explicitly spawns an external process, so would use mod_cgi. You could then spawn a Node.js process.

You would, however, need to write a real CGI program and not use a fragment of HTML with embedded JS that depends on browser APIs.

#!/usr/bin/env node

process.stdout.write("Content-Type: text/plain\r\n\r\n");
process.stdout.write("Hello, world");

CGI isn't very efficient, and Node would be an odd choice of language. If you need to go via Apache then it would usually make more sense to run a server using Node and then use mod_proxy to access it via Apache.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.