Enable Live Reload in Node.js Application

If you are a node.js developer, you might have faced the situation where you keep on changing the files in your app and continuously stopping and starting the node server. This is really frustrating process. Live reloading can be easily enabled in the node.js applications. In this article I will explain the simple steps to enable live reload feature in node.js app.

Step 1: Install the node-livereload npm package in your app using following command:

$ npm install -g livereload
# OR
$ npm install livereload --save-dev

Step 2: Open the app.js in your node app and add following lines:

var livereload = require('livereload');

// This is different form http.createServer() or app.createServer()
var reloadServer = livereload.createServer();

reloadServer.config.exts.push("jade");  // Enable live reload for jade files
reloadServer.watch(__dirname);  // Enable watch on complete app folder

// You can also enable watch on multiple folders:
reloadServer.watch([__dirname + "/js", __dirname + "/css"]);

By default this extension does not support live reloading for .jade file. If you are using jade template engine, you need to enable live reloading for .jade files as shown above.

Step 3: Install the extension

Install the live reload extension for your browser. Do not forget to enable the extension.

Now reload the node server and live reloading is up and running.

Written by Arvind Bhardwaj

Arvind is a Magento and WordPress expert with more than 6 years of industry wide experience.

Website: http://www.webspeaks.in/

One thought on “Enable Live Reload in Node.js Application

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × two =