How to run npm funct from js file
Asked
Active
Viewed 37 times
0
-
1Possible duplicate of [Execute a command line binary with Node.js](https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js) – Ivan Bacher Jul 26 '18 at 09:36
1 Answers
1
Yes, you can do this, here is the code:
var execSync = require('child_process').execSync;
var list = execSync('yarn list', { encoding: 'utf-8' });
console.log(list);
Viktor Vlasenko
- 1,962
- 10
- 15
-
any way i could save the output as a string or object, or anything else? – Darknjan994 Jul 26 '18 at 09:48
-
In `callback` function you get the output as a string in `list` argument – Viktor Vlasenko Jul 26 '18 at 10:06
-