Advertisement
magician11

injecting response into functions

Oct 21st, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sendHTMLToBrowser = require("../myCode/andrewsHelpers").sendHTMLToBrowser;
  2. //var execExternalCommand = require("./childProcesses").execExternalCommand;
  3. // import the exec function defined on the child_process module
  4. var exec = require('child_process').exec;
  5.  
  6. function start(response, request) {
  7.     console.log("Request handler 'start' was called");
  8.  
  9.     var body = '<!doctype html>'+
  10.         '<html lang="en">'+
  11.         '<head>'+
  12.         '<meta charset=UTF-8" />'+
  13.         '</head>'+
  14.         '<body>'+
  15.         '<p>Hello Andrew :)</p>'+
  16.         '</body>'+
  17.         '</html>';
  18.  
  19.     sendHTMLToBrowser(response, body);
  20. }
  21.  
  22. function linecount(response, request) {
  23.     console.log("Request handler 'linecount' was called.");
  24.    
  25.     // launch the command "cat *.js | wc -l"
  26.     exec('cat *.js | wc -l', function(err, stdout, stderr) {
  27.         // the command exited or the launching failed
  28.         if (err) {
  29.             // we had an error launching the process
  30.             console.log('child process exited with error code', err.code);
  31.             return;
  32.         }
  33.         sendHTMLToBrowser(response, stdout.toString());
  34.     });
  35. }
  36.  
  37. function executeCommand(command) {
  38.    
  39.     return result;
  40. }
  41.  
  42. exports.start = start;
  43. exports.linecount = linecount;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement