I am using gulp-nodemon
config directory includes only one file, server.js.
$.nodemon({
script: 'config/server.js',
watch: ['config/**/*.js']
})
.on('restart', function () {
setTimeout(function () {
$.livereload.changed();
}, 1000);
});
Output:
[gulp] [nodemon] v1.2.1
[gulp] [nodemon] to restart at any time, enter `rs`
[gulp] [nodemon] watching: config/**/*.js
[gulp] [nodemon] starting `node config/server.js`
[gulp] [nodemon] watching 34,325 files - this might cause high cpu usage. To reduce use "--watch".
If i include an ignore option it fixes.
ignore: [
'node_modules/**',
'bower_components/**'
]
Why does nodemon watch everything even when I tell it to watch only config directory?
Also it appears from the output it only watches the config directory [nodemon] watching: config/**/*.js
Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.
nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application. nodemon does not require any changes to your code or method of development. nodemon simply wraps your node application and keeps an eye on any files that have changed.
Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.
This seems to be a bug with nodemon itself, because I was able to reproduce it using the simple nodemon
command :
> nodemon --watch app server.js
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/**/*
[nodemon] starting `node server.js`
[nodemon] watching 72,981 files - this might cause high cpu usage. To reduce use "--watch"
The default behavior of nodemon
is to watch all the directories in the root of your project,
and to ignore some directories like node_modules
, bower_components
or .sass_cache
. This default ignore
don't work actually, but was fixed in this PR. Applying this fix, my output was just as expected.
> nodemon --watch app server.js
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/**/*
[nodemon] starting `node server.js`
I tested using both configurations, and even with the warning, my nodemon
was not refreshing on a file change that is not in the specified watched
directory, and working just as expected with no performance issue. It's more likely a false-positive warning to me.
But for now I advice you to stay with your ignore
rule until this is merged into nodemon
or another workaround is found.
Here some related issues about that : #46, #366 and #32
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With