Using a custom grunt task to start a node server, and watch
Grunt's server task starts a static server (very useful when developing single page apps), and is configured like this:
grunt.initConfig({
server: {
port: 3000,
base: './public'
}
});
I can keep it running by using it with watch (must be the last, since it blocks).
grunt server watch
To have it start a Node app, instead of just serving static assets, I use a custom task:
grunt.registerTask('server', 'Start a custom web server', function() {
grunt.log.writeln('Started web server on port 3000');
require('./app.js').listen(3000);
});
I then export it in app.js like this:
express = require('express');
app = module.exports = express();
....
Written by Uri Sharf
Related protips
2 Responses
Thanks! Simple but good tip. :)
Btw check out <a href="https://npmjs.org/package/tiny-lr">tiny-lr</a>. It allows you to setup a LiveReload server. Even though it's early in development it works very well already.
over 1 year ago
·
Thanks for this, nice and to the point i love it.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Backbonejs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#