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
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.
Open the command prompt or terminal: Open the command prompt (Windows) or terminal (macOS/Linux) on your computer.
Navigate to your project directory: Use the
cd
command to navigate to the root directory of your project.Install nodemon locally: Run the command
npm install --save-dev nodemon
to installnodemon
as a development dependency of your project.Open your package.json file: Open the
package.json
file in your project’s root directory using a text editor.Add a script to run nodemon: Look for the
"scripts"
section in yourpackage.json
file. If it doesn’t exist, you can create it. Add a new script to runnodemon
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
.
Save and close the package.json file: Save your changes and close the
package.json
file.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 ofnodemon
.
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