3

I am making a crud application on PERN Stack (PostgreSQL, Express,React.JS,Node.JS). In the step of setting up the server I tried to run the following command but it is not working,I installed the nodemon first using "npm install nodemon" command but even after this I am getting the following error. Command: nodemon index Error: nodemon: command not found Error Screenshot

I wanted to install the nodemon globally but it's not working. However in the tutorial which I am following this command executes properly and this is the output on that tutorial application. but i am not getting the same output when I run this command enter image description here

3 Answers3

1

If you installed nodemon locally using npm install nodemon, but it still shows:

nodemon: command not found

It's possible that the nodemon executable is not in your system's PATH. Here are a few steps to troubleshoot and resolve the issue:

  1. Check the node_modules/.bin directory:
    After installing nodemon locally, it should create a .bin directory inside your project's node_modules folder. The nodemon executable should be located in this directory. Check if it exists:
./node_modules/.bin/nodemon index
  1. Update your npm scripts:
    To avoid typing the entire path every time, you can update your package.json file to include a script for running the server with nodemon. Open your package.json file and add the following line to the "scripts" section:
"scripts": {
  "start": "nodemon index"
}

Then, you can run the server using the following command:

npm start
  1. Install nodemon globally (not recommended for production):
    If you still face issues, you can install nodemon globally, though this is not recommended for production projects. The global installation might require administrator privileges (sudo) on some systems.
npm install -g nodemon

After the global installation, you should be able to use nodemon directly from the command line:

nodemon index

Remember that installing packages globally may lead to version conflicts and is generally not recommended for projects, especially when working on multiple projects with different dependencies.

It's usually better to stick with the local installation within the project and use npm scripts to manage the commands. If you encounter any issues, double-check your installation and ensure you are in the correct project directory.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
-1

Check if it is installed globally:

npm list -g --depth=0

If not, run the following command with --save-dev flag.

npm install nodemon --save-dev

You can use force flag:

sudo npm install -g --force nodemon
Huzaifa
  • 484
  • 4
  • 8
-1

check your npm global installation path running npm bin -g after that check if your nodemon is installed globally: npm list -g nodemon.

and add your npm global bin to path export PATH="$PATH:$(npm bin -g)"

finally run your nodemon locally: npx nodemon index

Marcos Silva
  • 115
  • 5