How to use nodemon locally in your project if it is not working globally?

Are you having trouble getting nodemon to work globally on your computer? Don’t worry, you can still use it locally within your project. Here’s how

Hey there! Are you having trouble getting nodemon to work globally on your computer? Don’t worry, you can still use it locally within your project. Here’s how

Problem Statement
Nodemon is a utility that monitors for changes in your source code and automatically restarts your server. It’s a great tool for speeding up development, but sometimes it can be tricky to get it working globally on your computer. If you’re having trouble getting nodemon to work globally, don’t worry! You can still use it locally within your project. In this article, we’ll show you how to set up nodemon to run locally in your project and provide a step-by-step guide to help you get started. Let’s dive in!

First, you’ll need to install nodemon locally in your project. To do this, open the command prompt or terminal and navigate to the root directory of your project. Then, run the command npm install --save-dev nodemon. This will install nodemon as a development dependency of your project.

Once you have nodemon installed locally, you can create a script in your package.json file to run the local version of nodemon. Open your package.json file and look for the "scripts" section. If it doesn’t exist, you can create it like this:

"scripts": {
  "serve": "nodemon server.js"
}

This script tells npm to run the local version of nodemon and pass it the argument server.js. You can replace server.js with the name of the file you want to run with nodemon.

Now, you can use the command npm run serve to start your server with nodemon. This will use the local version of nodemon that you installed in your project.

And that’s it! You can now use nodemon locally within your project even if it doesn’t work globally on your computer.

Below I have added a step-by-step Guide If you still have a hard time setting it up.

  1. Open the command prompt or terminal: Open the command prompt (Windows) or terminal (macOS/Linux) on your computer.

  2. Navigate to your project directory: Use the cd command to navigate to the root directory of your project.

  3. Install nodemon locally: Run the command npm install --save-dev nodemon to install nodemon as a development dependency of your project.

  4. Open your package.json file: Open the package.json file in your project’s root directory using a text editor.

  5. Add a script to run nodemon: Look for the "scripts" section in your package.json file. If it doesn’t exist, you can create it. Add a new script to run nodemon like this:

"scripts": {
  "serve": "nodemon server.js"
}

Make sure to replace server.js with the name of the file you want to run with nodemon.

  1. Save and close the package.json file: Save your changes and close the package.json file.

  2. Run nodemon locally: Go back to the command prompt or terminal and run the command npm run serve. This will start your server using the local version of nodemon.

And that’s it! You can now use nodemon locally within your project by following these simple steps.

I hope this guide helps you get up and running with nodemon. Let me know in comments if this article help you find the nodemon-related problem

Did you find this article valuable?

Support Developer's Way by becoming a sponsor. Any amount is appreciated!