I'm doing this tutorial on NodeJS: http://www.nodebeginner.org.
Here is the code I find confusing:
var exec = require("child_process").exec;
function start(response) {
console.log("Request handler 'start' was called.");
var content = "empty";
exec("ls -lah", function(error, stdout, stderr) {
response.writeHead(200, {"Content-type":"text/plain"});
response.write(stdout);
console.log(stdout);
response.end();
});
}
I have a router that passes the http response to a request handler that calls the start
function. This is happening without a problem. However, the stdout
parameter is not returning anything in the browser or in the console. I understand that ls -lah
is supposed to give a list of files in the current directory. I have 5 other files in my directory, but nothing is being returned. Any ideas on what is happening here?