Why I am getting error of " nodemon command not found" while setting the server of my PERN Stack Application

huangapple go评论61阅读模式
英文:

Why I am getting error of " nodemon command not found" while setting the server of my PERN Stack Application

问题

I am making a CRUD application on the 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 nodemon first using the "npm install nodemon" command, but even after this, I am getting the following error.
Command: nodemon index
Error: nodemon: command not found

I wanted to install nodemon globally, but it's not working. However, in the tutorial 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.

英文:

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
Why I am getting error of " nodemon command not found" while setting the server of my PERN Stack Application

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
Why I am getting error of " nodemon command not found" while setting the server of my PERN Stack Application

答案1

得分: 1

如果您使用 npm install nodemon 在本地安装了 nodemon,但仍然显示以下错误:

> nodemon: command not found

可能是因为 nodemon 可执行文件不在您系统的 PATH 中。以下是一些排除故障和解决此问题的步骤:

  1. 检查 node_modules/.bin 目录:<br />
    在本地安装 nodemon 后,它应该在项目的 node_modules 文件夹内创建一个 .bin 目录。nodemon 可执行文件应该位于此目录中。请检查它是否存在:
./node_modules/.bin/nodemon index
  1. 更新您的 npm 脚本:<br />
    为了避免每次都输入完整路径,您可以更新您的 package.json 文件,包含一个使用 nodemon 运行服务器的脚本。打开您的 package.json 文件,将以下行添加到 "scripts" 部分:
"scripts": {
  "start": "nodemon index"
}

然后,您可以使用以下命令运行服务器:

npm start
  1. 全局安装 nodemon(不建议用于生产):<br />
    如果您仍然遇到问题,您可以全局安装 nodemon,尽管这不建议用于生产项目。全局安装可能需要在某些系统上使用管理员权限(sudo)。
npm install -g nodemon

全局安装后,您应该能够直接从命令行使用 nodemon:

nodemon index

请记住,全局安装软件包可能导致版本冲突,通常不建议用于项目,特别是在处理具有不同依赖关系的多个项目时。

通常最好坚持在项目中进行本地安装,并使用 npm 脚本来管理命令。如果遇到任何问题,请仔细检查您的安装并确保您在正确的项目目录中。

英文:

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:<br />
    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:<br />
    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:
&quot;scripts&quot;: {
  &quot;start&quot;: &quot;nodemon index&quot;
}

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

npm start
  1. Install nodemon globally (not recommended for production):<br />
    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.

答案2

得分: 0

尝试使用以下命令全局卸载 nodemon

npm uninstall -g nodemon

然后重新安装 nodemon 并确保再次使用 -g 标志安装,以确保它全局安装:

npm install -g nodemon

英文:

Try uninstalling nodemon globally using the following command:

npm uninstall -g nodemon

After this reinstall nodemon and make sure to install with -g flag again to be sure that its installed globally.

npm install -g nodemon

答案3

得分: -1

检查是否全局安装:

npm list -g --depth=0

如果没有安装,请使用 --save-dev 标志运行以下命令:

npm install nodemon --save-dev

您可以使用强制标志:

sudo npm install -g --force nodemon
英文:

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

答案4

得分: -1

检查您的 npm 全局安装路径,运行 npm bin -g,然后检查是否全局安装了 nodemon:npm list -g nodemon

将您的 npm 全局 bin 添加到路径中:export PATH="$PATH:$(npm bin -g)"

最后在本地运行 nodemon:npx nodemon index

英文:

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=&quot;$PATH:$(npm bin -g)&quot;

finally run your nodemon locally: npx nodemon index

huangapple
  • 本文由 发表于 2023年7月20日 15:39:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定