I'm running a Node project with Heroku as my main deploy target. In dev environment I'm using grunt to start the web server, however in production I prefer to launch the app directly with node app
Here's my Procfile:
web: bin/web
And bin/web:
#!/bin/sh
echo "NODE_ENV=" $NODE_ENV
if [ "$NODE_ENV" == "production" ]; then
echo "Starting the server with node app"
node app
else
echo "Starting the server using grunt"
grunt
fi
The first echo
is for debugging. heroku log is showing:
app[web.1]: NODE_ENV=
Basically, meaning NODE_ENV is not set. (and the app starts with grunt instead of node app
)
The docs say that "The NODE_ENV environment variable defaults to production, but you can override it if you wish"
What am I missing?
NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).
Heroku Web Interface The first step is to log into your account and go to the Heroku dashboard. Figure 1 illustrates my dashboard. Choose the application for which you want to set the environment variables. Once you select the application, it takes you to the overview page of that project.
We see that it in fact reads NODE_ENV and defaults to 'development' if it isn't set. This variable is exposed to applications via 'app.
I am the Node language owner at Heroku and the answer is simple: No. Do not check node_modules in to Heroku apps.
Not sure if you figured this out or not, but I had the same problem and fixed it using:
heroku config:set NODE_ENV=production
Via https://devcenter.heroku.com/articles/nodejs-support.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With