Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • Go Premium
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How can We Run an External Process with Node.js ?
Next article icon

Restart NodeJS Server Automatically With Nodemon

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

If you're building a NodeJS application and want to automatically restart the server whenever you make changes to your code, Nodemon is a great tool for that. It saves you time by eliminating the need to manually restart the server each time you update your code.

Below are the steps to create a NodeJS project and install Nodemon to automatically restart the server.

What is Nodemon?

Nodemon is a utility that monitors changes in files within a NodeJS application and automatically restarts the server when it detects any changes. Instead of manually stopping and starting the server every time you change your code, Nodemon takes care of this for you, saving valuable time and effort during development.

How to Install Nodemon?

Below are the following steps by which we can automatically restart the NodeJS server with Nodemon.

Step 1: Create a New NodeJS Project

mkdir my-node-project
cd my-node-project

Initialize the NodeJS project by creating a package.json file:

npm init -y

Step 2: Install Express

If you want to create a basic server using Express.js, you can install it using npm.

npm install express

Create the app.js file and write the below code.

JavaScript
const express = require('express');
const app = express();
const port = 3000;

// Simple route
app.get('/', (req, res) => {
    res.send('Hello, World!');
});

// Start the server
app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});

Step 4: Install Nodemon Globally

To install Nodemon globally on your system, run the following command:

npm install -g nodemon

This allows you to use the nodemon command from anywhere on your system.

Install Nodemon Locally (Recommended for Projects)

It’s generally a good practice to install Nodemon locally within your project to avoid version conflicts between global and local versions of Nodemon. To install Nodemon locally, run:

npm install --save-dev nodemon

This will install Nodemon as a development dependency. It will also add Nodemon to your package.json file under devDependencies.

Step 5: Create a Nodemon Script in package.json

To make it easier to run your server with Nodemon, you can create a script in your package.json. Open the package.json file, and under the "scripts" section, add the following

"scripts": {
    "start": "nodemon app.js"
}

This tells npm to use Nodemon to run the app.js file when you run npm start.

Step 6: Run Your Project with Nodemon

Now, instead of running node app.js to start your server, you can use the following command to start your server with Nodemon

npm start

Output

Nodemon will now automatically restart your server whenever you make changes to the app.js (or other watched files) and save them. For example, if you update the message sent by the server, you will see the changes immediately without needing to restart the server manually.

Why Use Nodemon?

We should use the Nodemon for the following reasons:

  • Automatic Restarts: Nodemon watches your application files and automatically restarts the server whenever there are changes, so you don’t need to manually stop and start it every time.
  • Improved Development Workflow: By automating the server restart process, Nodemon helps you focus more on writing code and testing functionality rather than managing the server.
  • File Watching: Nodemon can watch JavaScript files, JSON files, HTML, CSS, and other types of files that might affect your NodeJS application.

When to Use Nodemon?

Nodemon is primarily used in development environments, where continuous code changes and testing are common. However, it is generally not recommended for production environments. For production environments, you may want to use tools like PM2 that are optimized for running Node.js applications in production.

Nodemon’s Benefits for Development

Here are some of the key benefits of using Nodemon for your NodeJS development:

  • Improved Workflow: Automatically restart your server without needing to manually stop and start it, saving time during development.
  • Real-time Updates: As you modify your files, Nodemon watches for changes and immediately reloads the server with the new code.
  • Flexibility: Nodemon offers a variety of configuration options to customize its behavior to suit your development needs.
  • Speed: By running your server automatically, Nodemon helps you focus on writing code and testing features, instead of constantly restarting the server manually.
  • Integration with package.json: You can easily add Nodemon to your existing project using the npm or yarn package manager, and automate tasks through package.json scripts.

Conclusion

Nodemon is an essential tool for NodeJS development, helping automate the process of restarting your server every time you make a change to the code. By installing and configuring Nodemon, you can significantly improve your development workflow and focus more on writing code rather than managing server restarts. Whether you're building a small project or working on a large-scale application, Nodemon helps make the process more efficient and seamless.


Next Article
How can We Run an External Process with Node.js ?

A

AshishkrGoyal
Improve
Article Tags :
  • Node.js
  • Node.js-Basics

Similar Reads

    How can We Run an External Process with Node.js ?
    Running external processes from within a Node.js application is a common task that allows you to execute system commands, scripts, or other applications. Node.js provides several built-in modules for this purpose, including child_process, which allows you to spawn, fork, and execute processes. This
    4 min read
    How to connect mongodb Server with Node.js ?
    mongodb.connect() method is the method of the MongoDB module of the Node.js which is used to connect the database with our Node.js Application. This is an asynchronous method of the MongoDB module.Syntax:mongodb.connect(path,callbackfunction)Parameters: This method accept two parameters as mentioned
    1 min read
    How To Use Node Modules with npm and package.json
    NodeJS is a powerful runtime for server-side JavaScript & these modules are reusable pieces of code that can be easily imported and used in NodeJS applications. npm (Node Package Manager) is the default package manager for Node JS and is used to install, manage, and publish NodeJS packages. This
    3 min read
    URL Monitoring Service with Node and Express.js
    Learn to set up a URL Monitoring Service with NodeJS and ExpressJS. It tracks URL statuses and notifies of any changes. This course emphasizes simplicity for beginners while guiding on scalable and clean code practices. The system conducts health checks on multiple URLs to ensure availability over t
    3 min read
    URL Monitoring Service with Node and Express.js
    Learn to set up a URL Monitoring Service with NodeJS and ExpressJS. It tracks URL statuses and notifies of any changes. This course emphasizes simplicity for beginners while guiding on scalable and clean code practices. The system conducts health checks on multiple URLs to ensure availability over t
    3 min read
    How to Install and Manage Node using NVM on Godaddy Server ?
    Managing multiple versions of Node.js on your server can be quite a task, especially if you're developing or maintaining applications that require different versions. Node Version Manager (NVM) simplifies this process by allowing you to install and switch between different versions of Node.js easily
    3 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences