Grunt task to run a nodemon monitor of your node.js server
Run nodemon as a grunt task for easy configuration and integration with the rest of your workflow
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install grunt-nodemon --save-dev
Then add this line to your project's
The minimal usage of grunt-nodemon runs with a
nodemon:dev:script: 'index.js'options:args: 'dev'nodeArgs: '--debug'nodemonon'log'console.logeventcolour;;env:PORT: '8181'cwd: __dirnameignore: 'node_modules/**'ext: 'js,coffee'watch: 'server'delay: 1000legacyWatch: trueexec:options:exec: 'less'
A common use case is to run
nodemon with other tasks concurrently. It is also common to open a browser tab when starting a server, and reload that tab when the server code changes. These workflows can be achieved with the following config, which uses a custom
options.callback function, and grunt-concurrent to run nodemon, node-inspector, and watch in a single terminal tab:
concurrent:dev:tasks: 'nodemon' 'node-inspector' 'watch'options:logConcurrentOutput: truenodemon:dev:script: 'index.js'options:nodeArgs: '--debug'env:PORT: '5455'// omit this property if you aren't serving HTML files and// don't want to open a browser tab on startnodemonon'log'console.logeventcolour;;// opens browser on initial server startnodemonon'config:update'// Delay before server listens on portsetTimeoutrequire'open''';1000;;// refreshes browser when server rebootsnodemonon'restart'// Delay before server listens on portsetTimeoutrequire'fs'writeFileSync'.rebooted' 'rebooted';1000;;watch:server:files: '.rebooted'options:livereload: true
Note that using the callback config above assumes you have
open installed and are injecting a LiveReload script into your HTML file(s). You can use grunt-inject to inject the LiveReload script.
Script that nodemon runs and restarts when changes are detected.
List of arguments to be passed to your script.
List of arguments to be passed to node. The most common argument is
--debug-brk to start a debugging server.
// By default the nodemon output is loggednodemonon'log'console.logeventcolour;;;
Callback which receives the
nodemon object. This can be used to respond to changes in a running app, and then do cool things like LiveReload a web browser when the app restarts. See the nodemon docs for the full list of events you can tap into.
String globs Default:
String with comma separated file extensions to watch. By default, nodemon watches
List of additional folders to watch for changes.
Delay the restart of nodemon by a number of milliseconds when compiling a large amount of files so that the app doesn't needlessly restart after each file is changed.
If you wish to force nodemon to start with the legacy watch method. See https://github.com/remy/nodemon#help-my-changes-arent-being-detected for more details.
The current working directory to run your script from.
Hash of environment variables to pass to your script.
You can use nodemon to execute a command outside of node. Use this option to specify a command as a string with the argument being the script parameter above. You can read more on exec here.
0.3.0 - Updated to nodemon
0.2.1 - Updated README on npmjs.org with correct options.
0.2.0 - Updated to nodemon 1.0, added new
scriptand is a required property. Some properties were changed to match nodemon:
ext(now a string) to match nodemon.
nodemon can now be listed as a dependency in the package.json and grunt-nodemon will resolve the nodemon.js file's location correctly.
0.1.1 - Added
legacyWatch option thanks to @jonursenbach.
0.1.0 - Removed
debugBrk options as they are encapsulated by the
- Configs with the
debugBrkoptions will no longer work as expected. They simply need to be added to
0.0.10 - Added
nodeArgs option thanks to @eugeneiiim.
0.0.9 - Fixed bug when using
0.0.8 - Added error logging for incorrectly installed
0.0.7 - Added
debugBreak option thanks to @bchu.
0.0.6 - Added
0.0.5 - Added
0.0.4 - Added
nodemon as a proper dependency.
0.0.3 - Uses local version of
nodemon for convenience and versioning.
0.0.2 - Removes
.nodemonignore if it was previously generated and then the
ignoredFiles option is removed.
0.0.1 - Added warning if
nodemon isn't installed as a global module.
0.0.0 - Initial release