question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nodemon ignores changes in watched directories

See original GitHub issue

Hi! I’m working with a dead simple Express app in WSL 2 Ubuntu. Project resides on a mounted NTFS partition and its structure is the following:

app.js
models
|__author.js
|__book.js
node_modules
|__...
nodemon.json
package-lock.json
package.json
schema
|__schema.js

Now I cannot for the life of me figure out how to make Nodemon restart the server upon changes to files under ‘models’ and ‘schema’ directories. It is only triggered by changes in files that are in the root folder like app.js and nodemon.json. The nodemon.json is only 3 LOC:

{
  "watch": [ "schema", "models", "./" ]
}

Before that I tried nodemon --watch schema/ --watch models --watch . app. No luck. Seems like a bug to me.

  • Operating system/terminal environment: WSL2 Ubuntu on Win10 19042.572
  • Using Docker? No
  • Command you ran: nodemon app

Here is the output of nodemon --dump:

[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): schema/**/* models/**/* **/*
[nodemon] watching extensions: js,mjs,json
--------------
node: v15.0.1
nodemon: 2.0.6
command: /home/<me>/.nvm/versions/node/v15.0.1/bin/node /home/<me>/.nvm/versions/node/v15.0.1/bin/nodemon --dump
cwd: /mnt/e/dev/graphql_exercise/server
OS: linux x64
--------------
{
  run: false,
  system: { cwd: '/mnt/e/dev/graphql_exercise/server' },
  required: false,
  dirs: [
    '/mnt/e/dev/graphql_exercise/server/schema',
    '/mnt/e/dev/graphql_exercise/server/models',
    '/mnt/e/dev/graphql_exercise/server'
  ],
  timeout: 1000,
  options: {
    dump: true,
    watch: [ 'schema', 'models', './', re: /schema|models|\.\// ],
    ignore: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**',
      re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
    ],
    monitor: [
      '/mnt/e/dev/graphql_exercise/server/schema/**/*',
      '/mnt/e/dev/graphql_exercise/server/models/**/*',
      '/mnt/e/dev/graphql_exercise/server/**/*',
      '!**/.git/**',
      '!**/.nyc_output/**',
      '!**/.sass-cache/**',
      '!**/bower_components/**',
      '!**/coverage/**',
      '!**/node_modules/**'
    ],
    ignoreRoot: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**'
    ],
    restartable: 'rs',
    colours: true,
    execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
    stdin: true,
    runOnChangeOnly: false,
    verbose: false,
    signal: 'SIGUSR2',
    stdout: true,
    watchOptions: {},
    execOptions: {
      script: 'index.js',
      exec: 'node',
      args: [],
      scriptPosition: 0,
      nodeArgs: undefined,
      execArgs: [],
      ext: 'js,mjs,json',
      env: {}
    }
  },
  load: [Function (anonymous)],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [ '/mnt/e/dev/graphql_exercise/server/nodemon.json' ],
  watchInterval: null,
  signal: 'SIGUSR2',
  command: {
    raw: { executable: 'node', args: [ 'index.js' ] },
    string: 'node index.js'
  }
}
--------------

Expected behaviour

Server restart on changes in files in root folder as well as “schema” and “models” directories.

Actual behaviour

Nodemon ignores changes to files in some directories and triggered by changes to those directly in the root folder.

Steps to reproduce

Specify watch directories either via command line arguments or in nodemon.json.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
elspecalcommented, Nov 12, 2020

In the wake of that previous comment I looked for the issue on wsl and it turns out that the project needs to reside on the linux root file system in case of wsl2. now that i moved the project from ‘/mnt/e/…’ to ‘/home/…’, Nodemon is working as expected.

0reactions
github-actions[bot]commented, Jul 9, 2021

Automatically closing this issue due to lack of activity

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodemon ignore directory - Stack Overflow
In a Universal Javascript app, I would like nodemon to ignore client directory changes. I have tried the following ...
Read more >
ignored directory still triggers nodemon check causing high ...
I'm trying to ignore a folder but it is not working. Here is the output using the --verbose flag: [nodemon] 1.19.2 [nodemon] reading...
Read more >
nodemon
By default, nodemon will only restart when a .js JavaScript file changes. In some cases you will want to ignore some specific files,...
Read more >
Automatically restart Node.js apps with Nodemon
The essential tutorial for Nodemon, a utility for Node.js applications that monitors for changes and automatically restarts the server.
Read more >
nodemon ignore file - Code Examples & Solutions For This ...
nodemon --ignore PATTERN1 [--ignore PATTERN2] Example: nodemon --ignore 'dist/*.js' --ignore README.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found