[英]How to install nodemon Nodejs on macOS? nodemon keeping show : command not found
Currently I already install nodemon with command npm install -g nodemon
.目前我已经使用命令
npm install -g nodemon
。 And I got Permissions issue, so I do command with sudo npm install -g nodemon
and i did it.而且我遇到了权限问题,所以我使用
sudo npm install -g nodemon
执行命令,我做到了。 But when I make "nodeman" command was always show nodemon: command not found
.但是当我制作“nodeman”命令时,总是 show
nodemon: command not found
。
If for any reasons you are unable to set a Global PATH then under your current project directory, run如果由于任何原因您无法设置全局路径,那么在您当前的项目目录下,运行
npm install nodemon --save-dev
then under "scripts" in your package.json file, add "start": "nodemon app.js" like this -然后在 package.json 文件中的“脚本”下,像这样添加“start”:“nodemon app.js” -
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
then run然后运行
npm start
If you need to install nodemon globally on mac OS, try如果您需要在 mac OS 上全局安装 nodemon,请尝试
sudo npm install -g nodemon
. sudo npm install -g nodemon
。
Then you'll have to enter your password.然后你必须输入你的密码。 Once the installation is completed successfully, run
安装成功后,运行
nodemon -v
to check nodemon version on terminal.在终端上检查 nodemon 版本。
According to this , Create a new directory to store your global
packages.根据这个,创建一个新目录来存储你的
global
包。 So that there is no permission issue.这样就不存在权限问题了。
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Edit your .profile or .bash_profile to add the new location to your PATH:编辑您的.profile或.bash_profile以将新位置添加到您的 PATH:
export PATH=~/.npm-global/bin:$PATH
Then install the package without sudo
:然后安装没有
sudo
的软件包:
npm install -g nodemon
如果你想安装全局nodemon使用SUDO,因为如果你需要是全局用户,你需要是超级用户
The other answer is correct but my advice is that it's better to not install packages globally if you can help it, this makes your application self sufficient without relying on the environment and avoids versioning issues between applications.另一个答案是正确的,但我的建议是,如果您能提供帮助,最好不要全局安装软件包,这样可以使您的应用程序自给自足而不依赖环境,并避免应用程序之间的版本控制问题。
npm install -D nodemon
You can now execute nodemon from scripts
in package.json:您现在可以从 package.json 中的
scripts
执行 nodemon:
"scripts": {
"start": "nodemon src/index.js"
}
Or you can execute it yourself using npx
if you're in that directory from the terminal.或者,如果您在终端的该目录中,您可以使用
npx
自己执行它。 npx executes local scripts, eg npx nodemon --inspect ./src/index.js 8080
npx 执行本地脚本,例如
npx nodemon --inspect ./src/index.js 8080
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.