DEV Community

Ashade Samson
Ashade Samson

Posted on

Working with Nodemon in Node.js projects

While working with Node.js for Backend development, developers usually get tired with having to restart the server application everytime a change is made to the program logic. I was also caught up in this scenario while working with on a Node project recently.

In this article, I want to outline how this tedious process could be made easier by using Nodemon to automatically execute this repetitive task while working on Node.js projects.

Before I proceed, I want to let you know about the HNG internship that gives early career professionals in tech a chance to work on real-world projects and gives them the experience of a real-time workspace remotely. Check it out here HNG Internships

Moving forward, to work with Nodemon, I installed nodemon as a dependency in my project using npm
npm install nodemon
This takes a few seconds or minutes to execute depending on your bandwidth strength, and afterwards Nodemon is added as a dependency in the package.json file as seen below

{
  "dependencies": {
    "express": "^4.19.2",
    "nodemon": "^3.1.0"
  }
}
Enter fullscreen mode Exit fullscreen mode

After this, I adjusted the value of the "start" property in my package.json file to "nodemon app.js" where "app.js" is the name of the entry file for my application and I save the changes. Code shown below

{
  "scripts": {
    "start": "nodemon app.js"
  }
}
Enter fullscreen mode Exit fullscreen mode

After applying these changes, my server application automatically restarts and adjust to any changes I make to the program logic and I don't need to manually do that again. Once I run "npm start" at the first instance, the nodemon dependency takes care of restarting my server after any change is made.

This is one of the techniques I have learnt while building my portfolio in backend development and I look forward to expanding my horizon in this field as I enroll for the HNG11 internship.

I believe the internship will give me an opportunity to apply the concepts and techniques I have learnt so far in a real-world setting and a chance to collaborate with other like-minded developers. If you are someone who also needs this type of experience, do well to check it out here and learn more about the internship.

Thanks for reading this article, I hope you learnt something.

Top comments (0)