Q:

how do you run a commamd say npm install or rake as part of a node js application?

I have a node app in which i want to run a command or task like npm install or rake or git clone . I tried using child process exec , but is not running the npm install task. Is there a alternative way?

A:

If you want to execute a shell (or cmd if you're on Windows) command you can do it by using child_process.exec()
https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback 
Here is an example:
var exec = require('child_process').exec;
var child;

child = exec("pwd", function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
        console.log('exec error: ' + error);
    }
});

Just put npm install or git clone or whatever you want to execute instead of pwd when calling the exec function.

