dt801ts dt801ts - 2 months ago 5
Node.js Question

Is it okay to be starting a Node.js App on Heroku in this way?

"name": "******",
"version": "1.0.0",
"description": "*******",
"engines": {
"node": "6.3.1"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cd server && npm install && node app.js"
"author": "******",
"license": "ISC"

Specifically, is 'start' wonky? This is the only package.json configuration which has worked in deploying my app so far. Is 'npm install' in the start script a redundancy and/or might it cause lag on heroku side? Heroku does an npm install on build anyways right? So I'm just pointing it to the right node_modules to npm install?

Also, why will it only work with 'cd server && node app.js' and not 'node server/app.js' ?


It looks like your node app doesn't exist in the root of your project, which is why you'll need extra steps to install modules and start the app. By default, Heroku npm installs and starts from the root directory of your app (otherwise, how would it know which directory "is your app?")

You should add a postinstall script:

"postinstall": "cd server && npm install"

And simplify your start script to:

"start": "cd server && node app.js"

The postinstall script will ensure that your node modules are built during the build phase (and stored with your slug) - that way, your app won't have to npm install every time it starts up.