Search code examples
gruntjsgrunt-contrib-watch

grunt: serverreload and liverelaod


This is supposed to be very simple, but I spent hours and failed to make this work,

All I need is to make the server reload when server code is updated, and browser live reload when client code is updated.

This is my code,

please help me to find out what's wrong,

var path = require('path');
module.exports = function(grunt) {
  grunt.initConfig({
    express: {
      options: {
        port: 3000,
        open:'http://localhost:3000',
        hostname:'localhost',
        server: path.resolve('./app.js'),
        serverreload:true
      },
      load: {
        server: path.resolve('./app.js')
      }
    },
    watch: {
      express: {
        files: ['*/**'],
        tasks: ['express:load']
      }
    }
  });

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

  grunt.registerTask('server', ['express:load', 'express-keepalive', 'watch']);
};

Solution

  • I think you may run your server app with nodemon then watch your files separately with grunt to livereload.