2

I'm running the following:

const exec = require('child_process').exec;
let installProcess = exec('npm install');
    installProcess.stdout.pipe(process.stdout);
    installProcess.stderr.pipe(process.stderr);

But I get no output in my terminal, what else can I try?

1

2 Answers 2

5

The following ended up working for me:

const execSync = require('child_process').execSync;
execSync('npm install', {stdio:[0,1,2]});
1
  • Didn't you mean to write const execSync = require('child_process').execSync;? Nov 12, 2018 at 20:25
0

This works perfectly

const exec = require('child_process').exec;
const installProcess = exec('npm install --verbose');

installProcess.stdout.on('data', process.stdout.write);
installProcess.stderr.on('data', process.stdout.write);
installProcess.on('close', (code) => process.stdout.write(`exited with ${code}`));

and the result

❯ node index.js   
stderr: npm
stderr:  info it worked if it ends with ok
npm verb cli [ '/usr/local/Cellar/node/6.3.0/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]

stderr: npm verb 
stderr: correctMkdir /Users/bwin/.npm/_locks correctMkdir not in flight; initializing

stderr: npm
stderr:  info lifecycle [email protected]~preinstall: [email protected]

stderr: npm verb
stderr:  exit [ 0, true ]

stderr: npm info 
stderr: ok 

exited with 0      
1
  • 1
    This does not work for me, the only output i get is "exited with 0"
    – linuxdan
    Aug 22, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.