5. requestHandlers.js - exec

Created Saturday 30 November 2013

// exec is a non-boxing function. It uses a callback function to populate the content variable after "ls -lah" command finishes executing.
// But meanwhile the function start returns the content "empty"...

var exec = require ("child_process").exec;

function start () {

console.log ("Request handler 'start' was called");
var content = "empty";
exec ("ls -lah", function (error, stdout, stderr) {
content = stdout;
return content;

function upload () {

console.log ("Request handler 'upload' was called");
return "Hello Upload";

exports.start = start;
exports.upload = upload;