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
Best Answer
Until a better solution reveals itself, I'm having a (publicly accessible) PHP script launch the javascript by executing a shell command