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 config .\nodemon.json
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 13236 to restart
[nodemon] ignoring: node_modules/**/* logs/**/*
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./bin/www`
[nodemon] forking
[nodemon] child pid: 11684
[nodemon] watching 1094 files
When I make a change to a file in logs folder the output is:
[nodemon] files triggering change check: logs\something.js
[nodemon] changes after filters (before/after): 1/0
This is the same whether I use nodemon.json or CLI.
This is nodemon.json
{
"verbose": true,
"ignore": ["node_modules/*", "logs/*"]
}
and this is the CLI version
nodemon --ignore logs/ --verbose ./bin/www
Other colleagues confirmed the having the same issue.
nodemon -v:node -v:nodmon stop watching ignored folders.
nodemon seems to watch the ignored folders, causing high CPU usage when the number of files in the ignored folder grows big.
--dump
node: v10.16.3
nodemon: 1.19.2
command: C:\Program Files\nodejs\node.exe C:\Users\----\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js --ignore logs/ --verbose --dump ./bin/www
cwd: C:\Users\----
OS: win32 x64
--------------
{ run: false,
system: { cwd: 'C:\\Users\\----' },
required: false,
dirs: [ 'C:\\Users\\----' ],
timeout: 1000,
options:
{ ignore:
[ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
'logs/',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*|logs\// ],
verbose: true,
dump: true,
watch: [ '*.*', re: /.*\..*/ ],
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,
signal: 'SIGUSR2',
stdout: true,
watchOptions: {},
execOptions:
{ script: './bin/www',
exec: 'node',
args: [],
scriptPosition: 0,
nodeArgs: undefined,
execArgs: [],
ext: 'js,mjs,json',
env: {} },
monitor:
[ '*.*',
'!**/.git/**',
'!**/.nyc_output/**',
'!**/.sass-cache/**',
'!**/bower_components/**',
'!**/coverage/**',
'!**/node_modules/**',
'!C:\\Users\\----\\logs/**/*' ] },
load: [Function],
reset: [Function: reset],
lastStarted: 0,
loaded: [],
watchInterval: null,
signal: 'SIGUSR2',
command:
{ raw: { executable: 'node', args: [ './bin/www' ] },
string: 'node ./bin/www' } }
--------------
Is nodemon actually restarting? Because this line:
[nodemon] changes after filters (before/after): 1/0
Says that nodemon detected a change (1 file), but after the filter was applied there was no files (0 files). So nodemon should not have restarted.
I'm rereading your issue and it's not so much that ignore doesn't work, but that you're seeing high cpu (I'll update the subject).
I suspect that chokidar's (used for watching) ignore isn't picking the filter, but nodemon's internal ignore _is_ working which is why you're seeing the trigger.
Can you change the ignore config to this:
{
"verbose": true,
"ignore": ["node_modules/*", "logs"]
}
And report back? I believe it'll correctly ignore logs at the chokidar level and it won't spike your cpu.
Thanks for the quick reply. I changed the ignore config but no success. I get the same output.
I realized that node_modules is not being watched by default and therefore is working properly.
As it is clear adding logs folder to ignore in fact does not restart the project if there is a change in that folder but it is being watched and causes CPU spikes on changes to the folder. Also the number of watching files reported by nodemon increases as the number of files in this folder increases.
Can you run nodemon with the environment value DEBUG=nodemon:watch and share the output?
It outputs many lines in the console, including all files from the logs directory
nodemon:watch watching dir: C:\Users\----\logs\console\5d87248430745134103306c2.log +1ms
Can you try changing the ignore rule in nodemon.json to **/logs/** and see if that makes a difference?
On Mac, the first way worked, but I wonder if being on windows makes a difference here…
Yes it worked!
Thanks.
I think the docs needs to reflect this. One has to use --verbose flag to make sure ignored folders are truly being ignored.
@remy Had the same issue (even when the log file was in the same directory as nodemon.json). Got solved when doing */.log
Hi,
I'm encountering the same issue on Mac, the **/directory/* fixed issue of ignore files not being taken into account. But my server still restarts because of the 4 watches files has been changed while I did not make any change. That keeps happening.
Here is the beginning of the output before the restart:
[nodemon] 2.0.3
[nodemon] reading config ./nodemon.json
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 46285 to restart
[nodemon] ignoring: **/logs/**/* **/db/**/* **/static/**/* **/views/**/* **/robots.txt **/package*json **/.git/**/*
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 46287
[nodemon] watching 4 files
3000 is the magic port
And here is right before the restart:
[nodemon] files triggering change check: utils.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] utils.js
[nodemon] files triggering change check: server.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] server.js
[nodemon] files triggering change check: utils.js.map
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/0
[nodemon] files triggering change check: nodemon.json
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] nodemon.json
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 46545
[nodemon] files triggering change check: nodemon.json
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] nodemon.json
[nodemon] files triggering change check: utils.js.map
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/0
[nodemon] files triggering change check: utils.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] utils.js
[nodemon] files triggering change check: server.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] server.js
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 46563
3000 is the magic port
The directory I'm starting the server from is on a smb shared folder. Can that explain the file change while I'm not writing anything new in it?
Thanks.
Most helpful comment
Can you try changing the ignore rule in
nodemon.jsonto**/logs/**and see if that makes a difference?On Mac, the first way worked, but I wonder if being on windows makes a difference here…