How to Use Nodemon to Auto Reload Node.js
Nodemon is an open-source utility tool that helps automatically restart a Node server whenever a change in code is detected in development. In this lesson, we'll install Nodemon and introduce an application script that will start the Node server with Nodemon.
Automatic Reloading Using Nodemon#
📝 This lesson's quiz can be found - here.
🗒️ Solutions for this lesson's quiz can be found - here.
When developing our server application, there are going to be a lot of changes we're going to make to our code. We probably don't want to stop our running server and restart it every single time we make an update. Wouldn't it be nice if there was a third-party tool that did that for us? Well, there is, and it's called Nodemon!
Nodemon is a tool that will monitor for any changes in our source code and automatically restart our Node server when a change is detected. To install Nodemon, we'll run the npm install
command but this time use the -D
flag which is a shorthand version of --save-dev
. This indicates that the package to be installed is a development dependency. Development dependencies are packages that are only needed for local development.
server $: npm install -D nodemon
After nodemon
is installed, our package.json
file will list nodemon
in the devDependencies
list:
{
"name": "tinyhouse-v1-server",
"version": "0.1.0",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"nodemon": "^1.19.1"
}
}
This page is a preview of TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL