Node.js Heroku Deployment on Mac - sh: 1: nodemon: not found / npm ERR! `nodemon fileName.js` / npm ERR! Failed at the...start script
Heroku runs in a production environment by default so it does not install the dev dependencies.
If you don't want to reinstall nodemon as a dependency, which I think you shouldn't, because it's right place is in devDependencies, not in dependencies...
Instead, you can create a second npm script, in your package.json
, to avoid this error by running nodemon
only in your localhost:
"scripts": {
"start": "node fileName.js",
"start:dev": "nodemon fileName.js"
},
And when you want to run the project locally, just run in your terminal npm start:dev
and it will load fileName.js
with nodemon
.
While in Heroku, npm start
runs by default and loads fileName.js from a normal node command and you get rid of that error.
2019-05-08T18:13:40.319989+00:00 heroku[web.1]: State changed from crashed to starting
2019-05-08T18:13:41.000000+00:00 app[api]: Build succeeded
2019-05-08T18:13:42.658048+00:00 heroku[web.1]: Starting process with command npm start
2019-05-08T18:13:44.644005+00:00 app[web.1]:
2019-05-08T18:13:44.644025+00:00 app[web.1]: > [email protected] start /app
2019-05-08T18:13:44.644027+00:00 app[web.1]: > node fileName.js
2019-05-08T18:13:44.644028+00:00 app[web.1]:
2019-05-08T18:13:45.158694+00:00 app[web.1]: app is running on port 33333
2019-05-08T18:13:46.293205+00:00 heroku[web.1]: State changed from starting to up
2019-05-08T18:13:47.788861+00:00 heroku[router]: at=info method=GET path="/" host=yourURL.herokuapp.com request_id=hidden fwd="ip" dyno=web.1 connect=0ms service=11ms status=200 bytes=245 protocol=https
I made this post in hopes to help you avoid the time it took me to debug this issue.