node.js 我无法全局安装 nodemon,无法识别“nodemon”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17975999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I can′t install nodemon globally, "nodemon" not recognized
提问by RMontes13
i wanna use nodemon for monitoring my node.js app's, then i execute the next line command:
我想使用 nodemon 来监控我的 node.js 应用程序,然后我执行下一行命令:
npm install -g nodemon
or
或者
npm install nodemon -g
When I move to my app folder and try to to
当我移动到我的应用程序文件夹并尝试
nodemon app.js
The system tells to the next:
系统告诉下一个:
"nodemon 'is not recognized as an internal or external command, program or batch file.
“nodemon '不是内部或外部命令、程序或批处理文件。
回答by Chandu
Since node prefix is not in the PATH ENV variable , any of the globally installed modules are not getting recognized.
由于节点前缀不在 PATH ENV 变量中,因此无法识别任何全局安装的模块。
Please try this.
请试试这个。
Open cmd prompt
打开cmd提示
npm config get prefix
npm config 获取前缀
append the resulting path to PATH env variable.
将结果路径附加到 PATH 环境变量。
Now you should be able to run nodemon from any location.
现在您应该能够从任何位置运行 nodemon。
This is what i have done on my local machine
这是我在本地机器上所做的
C:\>npm config get prefix
C:\Users\username\AppData\Roaming\npm
C:\>set PATH=%PATH%;C:\Users\username\AppData\Roaming\npm;
C:\>nodemon
31 Jul 22:30:29 - [nodemon] v0.7.8
31 Jul 22:30:29 - [nodemon] to restart at any time, enter `rs`
31 Jul 22:30:29 - [nodemon] watching: C:\
31 Jul 22:30:29 - [nodemon] starting `node `
^CTerminate batch job (Y/N)? Y
回答by user1501382
I also got same error as you with this command:
使用此命令时,我也遇到了与您相同的错误:
$ sudo npm install -g nodemon
I just really switched as "root" and then just ran:
我只是真正切换为“root”,然后就跑了:
$ npm install -g nodemon
I think npm has a bug to not work with sudo, but it works fine when you are really "root".
我认为 npm 有一个无法使用的错误sudo,但是当您真正是“root”时它可以正常工作。
回答by kapil
You can add path to node packages in System Path variable. Add "C:\Users\UserName\AppData\Roaming\npm".
您可以在系统路径变量中添加节点包的路径。添加“C:\Users\UserName\AppData\Roaming\npm”。
回答by mustafa kemal tuna
There is a problem with integrated terminal of vs code. when I try in external terminal nodemon works. But in integrated terminal, it gives bash: nodemon: command not founderror.
vs code的集成终端有问题。当我尝试在外部终端 nodemon 工作时。但是在集成终端中,它会bash: nodemon: command not found出错。
so here is my solution
所以这是我的解决方案
install nodemonas development dependency
安装 nodemon作为开发依赖
npm install --save-dev nodemon
and change package.jsonof the project
并更改项目的package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"nodemon": "./node_modules/.bin/nodemon"
},
to run nodemontype into terminal in project folder
在项目文件夹中的终端中运行 nodemon类型
npm run nodemon
回答by Ajay Kumar
check out here :-
在这里查看:-
npm install -g nodemon
npm install -g nodemon
and then run
然后运行
$nodemon server.js
回答by Rinold
Single line solutionIn terminal
单线解决方案终端内
npm install -g --force nodemon
npm install -g --force nodemon
回答by bhanu sengar
This command worked for me.
这个命令对我有用。
If your global installation didn't work then install it in your development dependency.
如果您的全局安装不起作用,则将其安装在您的开发依赖项中。
npm install --save-dev nodemon
回答by Ryan B
Mine was I went to Control Panel and Repair the NodeJS app and tried to install again with npm install -g nodemonand now it works. Maybe you mixed up or something with Node.
我的是我去控制面板并修复 NodeJS 应用程序并尝试再次安装npm install -g nodemon,现在它可以工作了。也许你和 Node.js 搞混了。
回答by Charitha Goonewardena
Even after adding path to System Path variable it did not work for me using nodemon. Then i used npm run serveto run the server. now it is up and running. Btw i am a windows user
即使在将路径添加到系统路径变量后,它也不适用于我使用nodemon. 然后我用来npm run serve运行服务器。现在它已经启动并运行了。顺便说一句,我是 Windows 用户
回答by pcnate
Linux users: I would highly suggest not using sudo or root user to install npm packages. This could become a security problem especially on a production system. I would also suggest not trying to hack permissions as I have hosed an Ubuntu system by not reading the warning on the npmjs procedure.
Linux 用户:我强烈建议不要使用 sudo 或 root 用户安装 npm 包。这可能会成为一个安全问题,尤其是在生产系统上。我还建议不要试图破解权限,因为我已经通过不阅读 npmjs 程序上的警告来管理 Ubuntu 系统。
It would be better to configure npm to use a folder owned by the current user. Simplest approach
最好将 npm 配置为使用当前用户拥有的文件夹。最简单的方法
wget https://raw.githubusercontent.com/pcnate/npm-configure/master/add-npm-global.sh -q -O - | bash
npm install -g nodemon
Or get the code script on githubto see how it works
See details on the npmjs website
在npmjs 网站上查看详细信息

