I would like to run an additional script before the main 'node app' is called. So, i have changed my package.json as follows:
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": ["node helloworld", "node app"]
},
...
Then from command line i run:
npm start
This doesn't work. Is there way to call one script before the another at Node.js startup? Thank you
Don't use an array for the processes. Separate them with a semicolon instead like this.
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node helloworld; node app"
},
...
You could do something with child_process, e.g.
// start.js
var cp = require('child_process');
cp.exec("node helloworld", function (err) {
require("./app");
});
And simply:
"scripts": {
"start": ["node start"]
}