Skip to content

How to hot reload Node.Js application

Simple way to hot reload your Node.js application is: using Nodemon

npm install -g nodemon

In your package.json, rewrite the npm start

"scripts": {
"start": "nodemon ./bin/www"
}

We can run nodemon directly by: nodemon ./bin/www but with using npm start, we don’t need to remmember the nodemon command. It’s really useful when you work on many projects at the same time.

Nodemon supports local, global configuration files and command line arguments. Check it out

Sample configuration for Nodemon https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md

{
  "restartable": "rs",
  "ignore": [
    ".git",
    "node_modules/**/node_modules"
  ],
  "verbose": true,
  "execMap": {
    "js": "node --harmony"
  },
  "events": {
    "restart": "osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
  },
  "watch": [
    "test/fixtures/",
    "test/samples/"
  ],
  "env": {
    "NODE_ENV": "development"
  },
  "ext": "js,json"
}

Then, let’s run npm start and enjoy 🙂

Published inCodingNodejs

Be First to Comment

Leave a Reply

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