/grunt-develop

Grunt Task to run a Node.js Server while developing, auto-reloading on change.

Primary LanguageJavaScriptMIT LicenseMIT

grunt-develop Build Status

Run a Node.js application for development, with support for auto-reload.

Notes:

  • Requires Grunt >= 0.4.0;
  • does not provide a file-watch, grunt-contrib-watch is helpful here;
  • no need to modify/export your server or alter your applications code;
  • is not blocking (the task completes immediately and the application will run in the background);
  • reloads cleanly the application when the task is called again, allowing for auto-reload.

Install

$ npm install grunt-develop

Basic Gruntfile.js Example

module.exports = function(grunt) {

  grunt.initConfig({
    develop: {
      server: {
        file: 'app.js',
        nodeArgs: ['--debug'],            // optional
        args: ['appArg1', 'appArg2']      // optional
      }
    }
  });

  grunt.loadNpmTasks('grunt-develop');

  grunt.registerTask('default', ['develop']);

};

A more complex Gruntfile.js

To support auto-reload on changes, for example:

module.exports = function(grunt) {

  grunt.initConfig({
    watch: {
      js: {
        files: [
          'app.js',
          'routes/**/*.js',
          'lib/*.js'
        ],
        tasks: ['develop'],
        options: { nospawn: true }
      }
    },
    develop: {
      server: {
        file: 'app.js'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-develop');

  grunt.registerTask('default', ['develop']);

};

The nospawn is required to keep the grunt context in which grunt-develop is running your application.

Then you can run grunt as the following and get automatic restart of the application on file changes:

$ grunt

You may add any other task in the watch, like JS linting, asset compiling, etc. and customize the watch to your needs. See grunt-contrib-watch.

License (MIT)

Copyright (c) 2013, Edward Hotchkiss.