Use npm start to launch node app
There are many ways to fire up a node app. Quick, which one of these is right for your app?
- node app.js
- coffee app.coffee
- supervise -x ./node_modules/.bin/iced -e js,coffee,iced,jade,styl,css --no-restart-on exit app.iced
- ./launch.js
Ugh. And what happens when you switch between apps? Wait, was this one monitored with supervisor? No, wait, it's a CoffeeScript app with a standard JavaScript launcher, right?
Forget all of that noise. Open up your package.json and add this line:
{ "scripts": { "start": "node app.js"} },
Replace "node app.js" with whatever you use to start your app. Do this for every app you work on. Next time you need to fire up your app, just do this:
npm start
That's it. Now your startup is the same across all apps and you never have to think about any ridiculous mishmash of commands and flags. Either do your coworkers. Or any contributors. Success.
Written by Adam Yanalunas
Related protips
2 Responses
i do like the simplicity of it. my challenge is I'm not sure how to translate that to make it work on dokku, nodejitsu or modulus. they all seem to pick up the main entry point as 'app.js', which is not what I want. any suggestions?
In your package.json
specify the "main" key with the name of your startup script. Alternately, under the "scripts" object you can have a "start" key with similar values.
Here's an example package.json
I used for a little toy site I hosted on Heroku.
https://github.com/adamyanalunas/californiagrowlerfills.com/blob/master/package.json
Also, don't forget to check the docs. Here's a highlight from Nodejitsu:
https://www.nodejitsu.com/documentation/appendix/package-json/