Reputation: 305
Is it possible to start both angular default server(port:4200) and node.js(port:8080) using npm?
packages.json:
"start":"ng serve && node server.js"
If I run npm start, only angular's server(4200) is started running but not node's server(8080).
Is there a way to make both the servers has to run on their respective ports at same time using npm.
Need someone's help.
Upvotes: 2
Views: 3683
Reputation: 299
Inside of your package.json you can add
"start": "ng serve --open | nodemon node/",
Keep in mind that it is relative to your package.json location , so in the above example node is a subdirectory inside my angular project. This will also open a browser for you. If you don't want the browser to open just remove the --open
Full example
"scripts": {
"ng": "ng",
"start": "ng serve --open | nodemon node/",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
You can use gulp of course as the other answer suggests
Upvotes: 7
Reputation: 18105
If you need to have control over startup scripts, maybe it is a better approach to use a tool directly designed for that. (Workflow automation)
May I recommend gulp.js: with it, you can define scripts that will run in a sequence or paralell.
A very basic example:
gulp.task('node-server-start', function (cb) {
spawn('node', ['server.js'], {stdio: 'inherit'})
});
gulp.task('ng-serve', function (cb) {
spawn('ng', ['serve'], {stdio: 'inherit'})
});
gulp.task('start', ['ng-serve', 'node-server-start'], function () {
});
And you just start it wih gulp start
Upvotes: 0