Gathering detailed insights and metrics for gulp-nodemon
Gathering detailed insights and metrics for gulp-nodemon
Gathering detailed insights and metrics for gulp-nodemon
Gathering detailed insights and metrics for gulp-nodemon
npm install gulp-nodemon
Typescript
Module System
Node Version
NPM Version
50.1
Supply Chain
83.9
Quality
66.4
Maintenance
50
Vulnerability
97.9
License
JavaScript (100%)
Total Downloads
21,698,775
Last Day
4,043
Last Week
27,650
Last Month
137,811
Last Year
1,788,966
526 Stars
150 Commits
76 Forks
15 Watching
10 Branches
25 Contributors
Minified
Minified + Gzipped
Latest Version
2.5.0
Package Id
gulp-nodemon@2.5.0
Size
4.84 kB
NPM Version
6.11.3
Node Version
10.17.0
Publised On
04 Mar 2020
Cumulative downloads
Total Downloads
Last day
-27.7%
4,043
Compared to previous day
Last week
-8.4%
27,650
Compared to previous week
Last month
-13%
137,811
Compared to previous month
Last year
-11.4%
1,788,966
Compared to previous year
6
gulp + nodemon + convenience
1$ npm install --save-dev gulp-nodemon
Gulp-nodemon is almost exactly like regular nodemon, but it's made for use with gulp tasks.
Gulp-nodemon takes an options object just like the original.
Example below will start server.js
in development
mode and watch for changes, as well as watch all .html
and .js
files in the directory.
1gulp.task('start', function (done) { 2 nodemon({ 3 script: 'server.js' 4 , ext: 'js html' 5 , env: { 'NODE_ENV': 'development' } 6 , done: done 7 }) 8})
NOTE: This feature requires Node v0.12 because of child_process.spawnSync
.
Gulp-nodemon can synchronously perform build tasks on restart.
If you want to lint your code when you make changes that's easy to do with a simple event. But what if you need to wait while your project re-builds before you start it up again? This isn't possible with vanilla nodemon, and can be tedious to implement yourself, but it's easy with gulp-nodemon:
1nodemon({ 2 script: 'index.js' 3, tasks: ['browserify'] 4})
What if you want to decouple your build processes by language? Or even by file? Easy, just set the tasks
option to a function. Gulp-nodemon will pass you the list of changed files and it'll let you return a list of tasks you want run.
NOTE: If you manually restart the server (rs
) this function will receive a changedFiles === undefined
so check it and return the tasks
because it expects an array to be returned.
1nodemon({ 2 script: './index.js' 3, ext: 'js css' 4, tasks: function (changedFiles) { 5 var tasks = [] 6 if (!changedFiles) return tasks; 7 changedFiles.forEach(function (file) { 8 if (path.extname(file) === '.js' && !~tasks.indexOf('lint')) tasks.push('lint') 9 if (path.extname(file) === '.css' && !~tasks.indexOf('cssmin')) tasks.push('cssmin') 10 }) 11 return tasks 12 } 13})
gulp-nodemon returns a stream just like any other NodeJS stream, except for the on
method, which conveniently accepts gulp task names in addition to the typical function.
[event]
is an event name as a string. See nodemon events.[tasks]
An array of gulp task names or a function to execute.event
is an event name as a string. See nodemon events.The following example will run your code with nodemon, lint it when you make changes, and log a message when nodemon runs it again.
1// Gulpfile.js 2var gulp = require('gulp') 3 , nodemon = require('gulp-nodemon') 4 , jshint = require('gulp-jshint') 5 6gulp.task('lint', function () { 7 gulp.src('./**/*.js') 8 .pipe(jshint()) 9}) 10 11gulp.task('develop', function (done) { 12 var stream = nodemon({ script: 'server.js' 13 , ext: 'html js' 14 , ignore: ['ignored.js'] 15 , tasks: ['lint'] }) 16 , done: done 17 18 stream 19 .on('restart', function () { 20 console.log('restarted!') 21 }) 22 .on('crash', function() { 23 console.error('Application has crashed!\n') 24 stream.emit('restart', 10) // restart the server in 10 seconds 25 }) 26})
You can also plug an external version or fork of nodemon
1gulp.task('pluggable', function() { 2 nodemon({ nodemon: require('nodemon'), 3 script: 'server.js'}) 4})
The bunyan logger includes a bunyan
script that beautifies JSON logging when piped to it. Here's how you can you can pipe your output to bunyan
when using gulp-nodemon
:
1gulp.task('run', ['default', 'watch'], function(done) { 2 var nodemon = require('gulp-nodemon'), 3 spawn = require('child_process').spawn, 4 bunyan 5 6 nodemon({ 7 script: paths.server, 8 ext: 'js json', 9 ignore: [ 10 'var/', 11 'node_modules/' 12 ], 13 watch: [paths.etc, paths.src], 14 stdout: false, 15 readable: false, 16 done: done 17 }) 18 .on('readable', function() { 19 20 // free memory 21 bunyan && bunyan.kill() 22 23 bunyan = spawn('./node_modules/bunyan/bin/bunyan', [ 24 '--output', 'short', 25 '--color' 26 ]) 27 28 bunyan.stdout.pipe(process.stdout) 29 bunyan.stderr.pipe(process.stderr) 30 31 this.stdout.pipe(bunyan.stdin) 32 this.stderr.pipe(bunyan.stdin) 33 }); 34})
gulp-nodemon
with React, Browserify, Babel, ES2015, etc.Gulp-nodemon is made to work with the "groovy" new tools like Babel, JSX, and other JavaScript compilers/bundlers/transpilers.
In gulp-nodemon land, you'll want one task for compilation that uses an on-disk cache (e.g. gulp-file-cache
, gulp-cache-money
) along with your bundler (e.g. gulp-babel
, gulp-react
, etc.). Then you'll put nodemon({})
in another task and pass the entire compile task in your config:
1var gulp = require('gulp') 2 , nodemon = require('gulp-nodemon') 3 , babel = require('gulp-babel') 4 , Cache = require('gulp-file-cache') 5 6var cache = new Cache(); 7 8gulp.task('compile', function () { 9 var stream = gulp.src('./src/**/*.js') // your ES2015 code 10 .pipe(cache.filter()) // remember files 11 .pipe(babel({ ... })) // compile new ones 12 .pipe(cache.cache()) // cache them 13 .pipe(gulp.dest('./dist')) // write them 14 return stream // important for gulp-nodemon to wait for completion 15}) 16 17gulp.task('watch', ['compile'], function (done) { 18 var stream = nodemon({ 19 script: 'dist/' // run ES5 code 20 , watch: 'src' // watch ES2015 code 21 , tasks: ['compile'] // compile synchronously onChange 22 , done: done 23 }) 24 25 return stream 26})
The cache keeps your development flow moving quickly and the return stream
line ensure that your tasks get run in order. If you want them to run async, just remove that line.
gulp-nodemon
with browser-sync
Some people want to use browser-sync
. That's totally fine, just start browser sync in the same task as nodemon({})
and use gulp-nodemon's .on('start', function () {})
to trigger browser-sync. Don't use the .on('restart')
event because it will fire before your app is up and running.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 5/12 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
31 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More