Setup Nodemon to automatically restart the server

Patricio López
InstructorPatricio López
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

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].

[00:00] 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.

[00:15] 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.

[00:34] We add a new script and we call it dev. It will run nodemon on our index file.

[00:41] 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.

Tobi Taiwo
Tobi Taiwo
~ 6 years ago

The tutorial specify the src directory, what if there is a scenario where all files are in the root direction not in another folder. how will the --watch [dir] be specified

Markdown supported.
Become a member to join the discussionEnroll Today