For example sake, I'm running the most basic webServer in node (I'm using windows) with the following code (named server.js):
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 would like to run this as a child process, and am successfully doing so with the following:
var exec = require('child_process').exec;
var serv = exec('node server.js', function(error, stdout, stderr){
console.log('outputs & errors:' + error, stdout, stderr);
});
However, I receive nothing once I run the second file. No "outputs & errors", no "Server running at...". If I type localhost:1337 in a browser, I get "hello world" though, so I know it's running. Is there a way to pipe that "server running..." so I can be "sure" it's listening?