Can Node.js launch scripts on the server?

Problem

Can Node.js launch scripts on the server it is installed on? Scripts like bash scripts or PHP scripts, for example to resize pictures?

If so, how how is it? Can you point me to a documentation page, please?

Thanks,
Dan

Problem courtesy of: dan

Solution

Yes it is possible. The following give a demonstration:

  1. http://www.dzone.com/snippets/execute-unix-command-nodejs
  2. http://groups.google.com/group/nodejs/browse_thread/thread/e3d00bb0e48dd760?pli=1

You can also perform tasks such as spawning child processes, and clustering.

Executing a unix command:

var exec = require('child_process').exec;
child = exec("something", function (error, stdout, stderr) {
  sys.print('stdout: ' + stdout);
  sys.print('stderr: ' + stderr);
  if (error !== null) {
    console.log('exec error: ' + error);
  }
});

See Node.js Documentation for more: http://nodejs.org/api/child_process.html

Solution courtesy of: Jack

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.