0

I've got a javascript file on a RHEL server, which I can run (when communicating through console / SSH to the server) using 'node script.js'.

However, I'd like a user to be able to activate the script by visiting a URL.

I tried actually running a http server in script.js, but couldn't figure out what to put as the IP (after all, it's on an existing linux server! I can already publicly read the script.js file contents through the browser), using this template;

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

I've no idea what IP I'd specify for the server, or what URL I'd launch the script with;
obviously I'm lacking some pretty important conceptual understandings of what exactly Node.js does.

So; how would I do this?
Try to emulate the http server thing above, or somehow access the command prompt via a server-side script, in PHP or something?

Thanks

1
  • (if you're interested, I'm using Node.js because my program depends highly on concurrency, and I've reached big headaches in installing pthreads for PHP because I can't Yum php-devel - which is needed to allow the PECL installation of pthreads to use 'phpize()' - because Yum has no base repo because something something registration something I'm going to cut off all my limbs) – Anti Earth Sep 25 '13 at 13:54
0

Until a better solution reveals itself, I'm having a (publicly accessible) PHP script launch the javascript by executing a shell command

exec("node javascript.js params");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.