节点 js 服务器的终端无法识别 nodemon 命令
nodemon command is not recognized in terminal for node js server
我正在 https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens 进行 node.js 服务器设置。我是 node.js 的新人。我正在安装 npm install nodemon --save
。但是当我运行服务器有这个nodemon server.js
。
在终端中显示:
nodemon is not recognized as internal or external command, operable
program or batch file
node server.js
命令正在运行并启动了服务器,但是 nodemon
命令没有运行。
我从 https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens 视频中设置了节点 js 服务器。
我不知道为什么它不起作用我已经尝试了一些安装 nodemon 的命令。
npm install -g nodemon
npm install -g nodemon --save
npm install --save-dev nodemon
npm install -g nodemon@debug
npm install -g --force nodemon
我看过一个link I can´t install nodemon globally, "nodemon" not recognized,但是我的项目位置在D盘,不知道怎么设置路径。
我要运行nodemon server.js
。如果有人有想法,请分享。提前致谢。
您需要全局安装它
npm install -g nodemon
# or if using yarn
yarn global add nodemon
然后就可以在路径上使用了(我现在看到你已经试过了,但是没有用,你的路径可能是乱七八糟的)
如果您想使用本地安装的版本,而不是全局安装,那么您可以在 package.json
中创建一个脚本
"scripts": {
"serve": "nodemon server.js"
},
然后使用
npm run serve
可选,如果使用纱线
# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve
npm 然后会在您的本地 node_modules 文件夹中查找,然后再在您的全局模块中查找命令
是否需要全局安装?你需要能够 运行 nodemon server.js
吗?如果没有,您总是可以从本地项目目录中调用它。应该在这里:
node_modules/.bin/nodemon
由于节点前缀不在 PATH ENV 变量中,因此无法识别任何全局安装的模块。
请试试这个。
打开cmd提示符
npm 配置获取前缀
将生成的路径附加到 PATH 环境变量。
现在您应该可以从任何位置 运行 nodemon。
试试这个 link 并遵循 it.fixing npm 权限
https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory
我遇到了同样的问题。我已经将 nodemon 安装为开发依赖项,当我尝试启动服务器时,它给出了消息
nodemon is not recognized as internal or external command, operable
program or batch file
然后我将它安装到全局并尝试启动服务器并且成功了!
npm install -g nodemon
首先,编写 npm install --save nodemon
然后在 package.json 中写入以下内容
"scripts": {
"server": "nodemon server.js"
},
然后写
npm run server
您只需输入 nodemon
即可 运行 您的节点应用程序
它首先 运行 index.js
您可以轻松地将入口点放入该文件中。
如果你还没有安装 nodemon 那么你必须先通过
安装它
npm install -g nodemon
如果您遇到任何权限错误,请使用
sudo npm install -g nodemon
你可以通过
检查nodemon是否存在
nodemon -v
这一行解决了我在 CMD 中的问题:
npm install --save-dev nodemon
全局安装nodemon:
C:\>npm install -g nodemon
获取前缀:
C:\>npm config get prefix
您将在控制台中获得如下输出:
C:\Users\Family\.node_modules_global
复制它。
设置路径。
转到高级系统设置→环境变量→单击新建(在用户变量下)→将显示弹出表单→传递以下值:
variable name = path,
variable value = Copy output from your console
现在运行 Nodemon:
C:\>nodemon .
运行 这个命令:
npm install nodemon -g
现在它将安装 nodemon,但我的案例的问题是它正在某处安装 nodemon else.I 添加了来自 (ProgramFiles(x86)) 的 Nodejs 路径,但这没有用,所以我找到了另一个解决方案。
- 运行 以上命令
安装时会出现一个安装nodemon的路径,然后
[请到下方link查看路径][1]
[1]: https://i.stack.imgur.com/ld2sU.png
- 将路径复制到 npm 并将其设置为环境变量
现在试试下面的命令,希望它会运行
nodemon YourAppName.js
删除 nodemon,因为它是一个开发依赖项并使用 node 代替它。
"scripts": {
"start": "node server.js"
},
这对我有用。
在我的开发机器上创建新的用户配置文件后遇到了同样的问题。
问题是我不是 运行 作为管理员的控制台(命令 prompt\powershell ISE)。
运行 作为管理员为我解决了这个问题。
以上所有选项都失败了,我找到了永久解决方案。
在 dependencies 和 run npm install
下的 package.json 中添加以下行。这会将 nodemon 包添加到 node_modules 然后你就可以开始编码了。
"nodemon": "^1.17.*"
要使用 nodemon,您必须全局安装它。
对于Windows
npm i -g nodemon
对于Mac
sudo npm i -g nodemon
如果您不想全局安装它,您可以通过 运行ning 命令 npm i nodemon
在您的项目文件夹中本地安装它。如果 运行 在本地,它将给出类似这样的错误:
nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
要删除此错误,请打开 package.json
文件并添加
"scripts": {
"server": "nodemon server.js"
},
然后就是 运行 命令
npm run server
你的 nodemon 将开始正常工作。
这可能来晚了,但最好说点什么:)
如果你不想安装 nodemon globbaly,你可以使用 npx
,它会在 运行 时安装包,并将作为全局包运行(请记住,它只是可用的目前并且在全球范围内不存在!)。
所以你只需要npx nodemon server.js
。
npx
可以从 npm@5.2.0
版本及更高版本开箱即用。
只需全局安装
npm install -g nodemon
它对我有用 Windows 10.
nodemon app.js
Set-ExecutionPolicy cmdlet 的默认执行策略受限 Windows。
您可以通过将此策略设置为无限制来尝试安装 nodemon。
执行命令:Set-ExecutionPolicy Unrestricted
然后尝试安装 nodemon 并执行命令:nodemon -v
我试过全局安装 nodemon,但这对我不起作用。
每当我尝试 运行 它总是向我显示错误:
nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
2。我找到了两个解决方案
解决方案 1:
我尝试的是更新 package.json 文件中的 "scripts" 并在其中添加了
"server": "nodemon app.js"
代码行上方和之后
npm run server
解决方案2:
按Windows键。
在搜索框中输入 "Path" 然后 select "Edit the system environment variables"
单击底部附近的 "Environment Variables"。
在 "System Variables" 部分双击 "Path" 变量。
点击右侧的"New"。
将其复制并粘贴到框中(替换 [用户名]):
C:\Users[用户名]\AppData\Roaming\npm
重新启动您的终端并 VSCode。
然后键入 nodemon app.js
到 运行 nodemon
我应用了解决方案 2,因为我们只需要 运行 nodemon [filename.js]
我已经这样修复了
卸载现有的本地 nodemon
npm 卸载 nodemon
重新全局安装。
npm i -g nodemon
无需全局安装nodemon。只是 运行 这个 npx nodemon 。就是这样。
在你的 packge.json 中试试:
放“./node_modules/.bin/nodemon”而不只是“nodemon”。
对我来说它有效。
对我来说,设置路径变量就足以解决问题:
步骤 1) 使用 npm install -g nodemon
全局安装 nodemon
步骤2)设置ENVIRONMENT VARIABLES
,通过在PATH变量中添加npm路径
1) 打开控制面板,搜索环境变量
2)点击打开环境变量
3) 创建新变量 NPM
将其设置为 nodemon 安装 cmd 输出中显示的 npm 路径(如 nodemon
安装屏幕截图所示):
4) 现在将NPM
变量添加到PATH
变量中:
步骤 3) 关闭 'cmd' 并打开一个新的并输入 nodemon --version
现在我们可以使用 nodemon 了:)
最好全局安装 nodemon,而不是作为项目的开发依赖。
npm install -g nodemon
官方 NPM CDN:Link
此包用于监视 javascript 文件中的更改并重新 运行 npm 启动,以便于开发目的。
这帮助我解决了启动 nodemon 和 graphql 服务器的相同问题
npm run dev
第 1 步:$ npm install nodemon
--> 在您的项目上安装 nodemon
第 2 步:在 package.json 文件的脚本中添加服务:
"scripts": {
"serve": "nodemon app.js" // you can change file name accordingly
}
第 3 步:$ npm run serve
如果系统禁用了 运行 脚本,也可能会出现此问题。为了启用它:
以管理员身份运行打开Windows PowerShell
执行:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
npm install -g nodemon
nodemon 应用程序
以下对我有用 windows 11.
- 在终端中输入
npm install
。 (与项目同目录)
- 然后从默认浏览器输入
npm run serve
到 运行 应用程序。
几分钟前我遇到了同样的错误,我是这样解决的:
1.全局安装“nodemon”
npm install nodemon -g
2。然后需要在环境变量中加入npm路径
要查找路径,请在终端中执行此操作:
npm config get prefix
您将得到如下所示的输出:C:\Users\user\AppData\Roaming\npm
如果您不确定如何在 Windows 上更新环境变量,请查看:Here
3。 运行 再次使用“nodemon”应用程序
在你 运行 应用程序之前,创建一个新终端以确保终端识别环境变量中的更改。
然后运行:
例如:
nodemon server.js
我正在 https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens 进行 node.js 服务器设置。我是 node.js 的新人。我正在安装 npm install nodemon --save
。但是当我运行服务器有这个nodemon server.js
。
在终端中显示:
nodemon is not recognized as internal or external command, operable program or batch file
node server.js
命令正在运行并启动了服务器,但是 nodemon
命令没有运行。
我从 https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens 视频中设置了节点 js 服务器。
我不知道为什么它不起作用我已经尝试了一些安装 nodemon 的命令。
npm install -g nodemon
npm install -g nodemon --save
npm install --save-dev nodemon
npm install -g nodemon@debug
npm install -g --force nodemon
我看过一个link I can´t install nodemon globally, "nodemon" not recognized,但是我的项目位置在D盘,不知道怎么设置路径。
我要运行nodemon server.js
。如果有人有想法,请分享。提前致谢。
您需要全局安装它
npm install -g nodemon
# or if using yarn
yarn global add nodemon
然后就可以在路径上使用了(我现在看到你已经试过了,但是没有用,你的路径可能是乱七八糟的)
如果您想使用本地安装的版本,而不是全局安装,那么您可以在 package.json
中创建一个脚本"scripts": {
"serve": "nodemon server.js"
},
然后使用
npm run serve
可选,如果使用纱线
# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve
npm 然后会在您的本地 node_modules 文件夹中查找,然后再在您的全局模块中查找命令
是否需要全局安装?你需要能够 运行 nodemon server.js
吗?如果没有,您总是可以从本地项目目录中调用它。应该在这里:
node_modules/.bin/nodemon
由于节点前缀不在 PATH ENV 变量中,因此无法识别任何全局安装的模块。 请试试这个。 打开cmd提示符 npm 配置获取前缀 将生成的路径附加到 PATH 环境变量。 现在您应该可以从任何位置 运行 nodemon。 试试这个 link 并遵循 it.fixing npm 权限 https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory
我遇到了同样的问题。我已经将 nodemon 安装为开发依赖项,当我尝试启动服务器时,它给出了消息
nodemon is not recognized as internal or external command, operable program or batch file
然后我将它安装到全局并尝试启动服务器并且成功了!
npm install -g nodemon
首先,编写 npm install --save nodemon 然后在 package.json 中写入以下内容
"scripts": {
"server": "nodemon server.js"
},
然后写
npm run server
您只需输入 nodemon
即可 运行 您的节点应用程序
它首先 运行 index.js
您可以轻松地将入口点放入该文件中。
如果你还没有安装 nodemon 那么你必须先通过
安装它npm install -g nodemon
如果您遇到任何权限错误,请使用
sudo npm install -g nodemon
你可以通过
检查nodemon是否存在nodemon -v
这一行解决了我在 CMD 中的问题:
npm install --save-dev nodemon
全局安装nodemon:
C:\>npm install -g nodemon
获取前缀:
C:\>npm config get prefix
您将在控制台中获得如下输出:
C:\Users\Family\.node_modules_global
复制它。
设置路径。
转到高级系统设置→环境变量→单击新建(在用户变量下)→将显示弹出表单→传递以下值:variable name = path, variable value = Copy output from your console
现在运行 Nodemon:
C:\>nodemon .
运行 这个命令:
npm install nodemon -g
现在它将安装 nodemon,但我的案例的问题是它正在某处安装 nodemon else.I 添加了来自 (ProgramFiles(x86)) 的 Nodejs 路径,但这没有用,所以我找到了另一个解决方案。
- 运行 以上命令
安装时会出现一个安装nodemon的路径,然后 [请到下方link查看路径][1]
[1]: https://i.stack.imgur.com/ld2sU.png
- 将路径复制到 npm 并将其设置为环境变量
现在试试下面的命令,希望它会运行
nodemon YourAppName.js
删除 nodemon,因为它是一个开发依赖项并使用 node 代替它。
"scripts": {
"start": "node server.js"
},
这对我有用。
在我的开发机器上创建新的用户配置文件后遇到了同样的问题。
问题是我不是 运行 作为管理员的控制台(命令 prompt\powershell ISE)。
运行 作为管理员为我解决了这个问题。
以上所有选项都失败了,我找到了永久解决方案。
在 dependencies 和 run npm install
下的 package.json 中添加以下行。这会将 nodemon 包添加到 node_modules 然后你就可以开始编码了。
"nodemon": "^1.17.*"
要使用 nodemon,您必须全局安装它。
对于Windows
npm i -g nodemon
对于Mac
sudo npm i -g nodemon
如果您不想全局安装它,您可以通过 运行ning 命令 npm i nodemon
在您的项目文件夹中本地安装它。如果 运行 在本地,它将给出类似这样的错误:
nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
要删除此错误,请打开 package.json
文件并添加
"scripts": {
"server": "nodemon server.js"
},
然后就是 运行 命令
npm run server
你的 nodemon 将开始正常工作。
这可能来晚了,但最好说点什么:)
如果你不想安装 nodemon globbaly,你可以使用 npx
,它会在 运行 时安装包,并将作为全局包运行(请记住,它只是可用的目前并且在全球范围内不存在!)。
所以你只需要npx nodemon server.js
。
npx
可以从npm@5.2.0
版本及更高版本开箱即用。
只需全局安装
npm install -g nodemon
它对我有用 Windows 10.
nodemon app.js
Set-ExecutionPolicy cmdlet 的默认执行策略受限 Windows。 您可以通过将此策略设置为无限制来尝试安装 nodemon。
执行命令:Set-ExecutionPolicy Unrestricted
然后尝试安装 nodemon 并执行命令:nodemon -v
我试过全局安装 nodemon,但这对我不起作用。 每当我尝试 运行 它总是向我显示错误:
nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
2。我找到了两个解决方案
解决方案 1:
我尝试的是更新 package.json 文件中的 "scripts" 并在其中添加了
"server": "nodemon app.js"
代码行上方和之后
npm run server
解决方案2:
按Windows键。
在搜索框中输入 "Path" 然后 select "Edit the system environment variables"
单击底部附近的 "Environment Variables"。
在 "System Variables" 部分双击 "Path" 变量。
点击右侧的"New"。
将其复制并粘贴到框中(替换 [用户名]):
C:\Users[用户名]\AppData\Roaming\npm
重新启动您的终端并 VSCode。
然后键入
nodemon app.js
到 运行 nodemon
我应用了解决方案 2,因为我们只需要 运行 nodemon [filename.js]
我已经这样修复了
卸载现有的本地 nodemon
npm 卸载 nodemon
重新全局安装。
npm i -g nodemon
无需全局安装nodemon。只是 运行 这个 npx nodemon
在你的 packge.json 中试试: 放“./node_modules/.bin/nodemon”而不只是“nodemon”。 对我来说它有效。
对我来说,设置路径变量就足以解决问题:
步骤 1) 使用 npm install -g nodemon
步骤2)设置ENVIRONMENT VARIABLES
,通过在PATH变量中添加npm路径
1) 打开控制面板,搜索环境变量
2)点击打开环境变量
3) 创建新变量 NPM
将其设置为 nodemon 安装 cmd 输出中显示的 npm 路径(如 nodemon
安装屏幕截图所示):
4) 现在将NPM
变量添加到PATH
变量中:
步骤 3) 关闭 'cmd' 并打开一个新的并输入 nodemon --version
现在我们可以使用 nodemon 了:)
最好全局安装 nodemon,而不是作为项目的开发依赖。
npm install -g nodemon
官方 NPM CDN:Link
此包用于监视 javascript 文件中的更改并重新 运行 npm 启动,以便于开发目的。
这帮助我解决了启动 nodemon 和 graphql 服务器的相同问题
npm run dev
第 1 步:$ npm install nodemon
--> 在您的项目上安装 nodemon
第 2 步:在 package.json 文件的脚本中添加服务:
"scripts": {
"serve": "nodemon app.js" // you can change file name accordingly
}
第 3 步:$ npm run serve
如果系统禁用了 运行 脚本,也可能会出现此问题。为了启用它:
以管理员身份运行打开Windows PowerShell
执行:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
npm install -g nodemon
nodemon 应用程序
以下对我有用 windows 11.
- 在终端中输入
npm install
。 (与项目同目录) - 然后从默认浏览器输入
npm run serve
到 运行 应用程序。
几分钟前我遇到了同样的错误,我是这样解决的:
1.全局安装“nodemon”
npm install nodemon -g
2。然后需要在环境变量中加入npm路径
要查找路径,请在终端中执行此操作:
npm config get prefix
您将得到如下所示的输出:C:\Users\user\AppData\Roaming\npm
如果您不确定如何在 Windows 上更新环境变量,请查看:Here
3。 运行 再次使用“nodemon”应用程序 在你 运行 应用程序之前,创建一个新终端以确保终端识别环境变量中的更改。 然后运行: 例如:
nodemon server.js