Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 984 of the free egghead.io lessons, plus get Node.js content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Setup Nodemon to automatically restart the server

1:02 Node.js lesson by

Soon or later, we get tired of having to manually restart our Node.js application. We will install and configure Nodemon to help us with that headache.

Remember to install it as a development dependency with yarn add --dev nodemon and limit its scope with --watch [dir].

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Soon or later, we get tired of having to manually restart our Node.js application. We will install and configure Nodemon to help us with that headache.

Remember to install it as a development dependency with yarn add --dev nodemon and limit its scope with --watch [dir].

The first step to improve our project structure is to create a source directory and relocate our entry file. Our main goal is to keep organized our application, and then remember to update our package.json file.

If everything is well, we should be able to restart the application and expect the same result. From this point, we don't want to keep manually restarting our application. Hopefully, there is a tool for that named nodemon, just remember to install it as a development dependency.

We add a new script and we call it dev. It will run nodemon on our index file.

In this case, we only care about changes on our source directory, so we can limit its scope with the watch flag. Going back to the terminal, we execute churn run dev. Now, we can go modify and save any of our files, and the server will automatically restart.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?