Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

    Setup Nodemon to automatically restart the server

    Patricio LópezPatricio López

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



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    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.