I have some custom testing script, which I can run with npm run test
command, which executes some Node script for starting e2e/unit tests. But before it I must star
Just install npm
:
npm install npm
Then in your program:
npm.commands.run('dev', (err) => { ... });
See the source for more info. The npm.command
object is an unofficial API for npm. Note that using exec
or spawn
to execute npm
is safer, since the API is unofficial.
You can use exec to run from script
import {series} from 'async';
const {exec} = require('child_process');
series([
() => exec('npm run dev'),
() => exec('npm run test')
]);
Use PM2, it is really usefull and easy...
npm install pm2
const pm2 = require('pm2');
pm2.start({
script: 'npm -- run monitorTheWeather',
autorestart : false
}, (err, apps) => {
pm2.disconnect()
if (err) { throw err }
})