jrutter
jrutter

Reputation: 3213

Can you call a shell script from an expressjs app?

Does anyone know if you can call a shell script from an expressjs app?

Im writing an app that I would like to move some files around after a git post-receive hook, but stumped on this part.

Upvotes: 5

Views: 6938

Answers (2)

rdegges
rdegges

Reputation: 33844

Yep! Since Express is just node, you can execute any command your server will allow using exec like so:

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

function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ls -la", function(error, stdout, stderr) {
  if (!error) {
    // things worked!
  } else {
    // things failed :(
  }
});

Upvotes: 7

Sterling Archer
Sterling Archer

Reputation: 22405

Express is just a framework for NodeJS.

NodeJS can run commands by using the process object, or the child_process object.

Upvotes: 3

Related Questions