Search code examples
node.jsnodemon

Nodemon not watching files


I setup Nodemon on a new folder but any changes I make aren't being watched.

My package.json looks like:

{
  "name": "express",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "dev": "nodemon --watch ./ ./app.js"
  },
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.17.1",
    "http-errors": "~1.6.3",
    "jade": "~1.11.0",
    "morgan": "~1.9.1"
  },
  "config": {
    "mongodbMemoryServer": {
      "version": "latest"
    }
  },
  "devDependencies": {
    "nodemon": "^2.0.4"
  }
}

and the directory structure is something like:

enter image description here

app.js defines all the middleware to be used but the server creation and port specification happens in ./bin/www.

I am not sure why this format is being followed, but I was asked to work on this existing template and I tried to setup nodemon to make the development process easier.


Solution

  • server creation and port specification happens in ./bin/www.

    Which means that you need to run ./bin/www instead of app.js (how can you start your server by running file that doesn't contain that logic).

    You should be good to go with

    "dev": "nodemon ./bin/www"
    

    I am not sure why this format is being followed

    Because it makes testing way easier (exporting the server object and loading it into your test files). Also because of logic separation.