Search code examples
node.jsherokunodemon

Deploying node app on heroku firing errors related to nodemon


I am trying to run my node app in heroku but I am getting this error which is related to nodemon dependency.

2018-12-16T21:32:51.891208+00:00 app[web.1]: sh: 1: nodemon: not found
2018-12-16T21:32:51.895084+00:00 app[web.1]: npm ERR! file sh
2018-12-16T21:32:51.895380+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-16T21:32:51.895627+00:00 app[web.1]: npm ERR! errno ENOENT
2018-12-16T21:32:51.895865+00:00 app[web.1]: npm ERR! syscall spawn
2018-12-16T21:32:51.896987+00:00 app[web.1]: npm ERR! turktutor_backend@1.0.0 start: `nodemon --watch`
2018-12-16T21:32:51.897151+00:00 app[web.1]: npm ERR! spawn ENOENT

I have my package.json like that:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --watch"
  },
"dependencies": {
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "express-validator": "^5.3.0",
    "googleapis": "^27.0.0",
    "jsonwebtoken": "^8.4.0",
    "mongoose": "^5.3.14",
    "mongoose-unique-validator": "^2.0.2",
    "nodemailer": "^4.7.0"
  },
  "devDependencies": {
    "morgan": "^1.9.1",
    "nodemon": "^1.18.7"
  }

i tried to follow the solution in this link that requires changing "Procfile" file, but heroku says that Procfile is no longer required for Node.js apps source

I am wondering if I need to install my devDependencies in heroku server by some command!

so please any help to solve this problem?


Solution

  • i figured out that heroku runs in a production environment by default so it does not install the dev dependencies so i created two diffrent npm scripts script in my package.json like that:

    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node index.js",
        "start:dev": "nodemon --watch"
    },
    

    and when i want to run the project locally i run npm run start:dev so it load index.js by nodemon, while in heroku npm start runs by default and load index.js from a normal node command.