I've started playing around with Koa, but so far have been unable to find a decent solution for automatically reloading the application upon code changes.
My understanding is that nodemon is the preferred solution in the Node universe, but I'm getting errors due to the --harmony
flag (required by Koa):
$ node_modules/.bin/nodemon /path/to/node-unstable/bin/node app.js
/path/to/node-unstable/bin/node --harmony $@
^^^^^^^
SyntaxError: Unexpected identifier
[nodemon] app crashed - waiting for file changes before starting...
node_modules/.bin/nodemon --harmony-generators app.js
should be sufficient
I would like to recommend you "pm2" : http://pm2.keymetrics.io/
pm2 is a process manager. It manages your applications states, so you can start, stop, restart and delete processes.
You can easily install pm2 (generally on your machine) typing: sudo npm install -g pm2
Basically pm2 when see some changes in your code, he restart your process istantly, if your process crash he will be restarted and the error will be logged.. For more information take a look on the documentation page: http://pm2.keymetrics.io/docs/usage/cluster-mode/
Setting the 'execMap' option in this gulp task works for me:
var nodemon = require('gulp-nodemon');
gulp.task('serve-dev', function() {
var options = {
script: './src/server/app.js',
execMap: {
"js": "node --harmony"
},
delayTime: 1,
env: {
'PORT': port,
'NODE_ENV': 'dev'
},
watch: ['./src/server/']
};
return nodemon(options);
});
Obviously your other options may differ, but I included the whole thing as it annoys me when I'm learning something to only see the bare minimum in an answer.
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