nodemon 未在 VS Code 终端中运行

问题描述 投票:0回答:5
PS D:\my-express-server> npm i nodemon

added 32 packages, and audited 90 packages in 6s

10 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
PS D:\my-express-server> nodemon -v
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.
At line:1 char:1
+ nodemon -v
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (nodemon:String) [], CommandNotFoundException

PS D:\my-express-server> nodemon .\server.js
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.
At line:1 char:1
+ nodemon .\server.js
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (nodemon:String) [], CommandNotFoundException

我想在 vs code 中完整运行nodemon,所以请给我解决方案。

node.js express npm nodemon
5个回答
0
投票

如果您还没有全局安装,则每次都必须在项目目录中安装

nodemon
。使用
npm install nodemon -g
。希望这有帮助。


0
投票

要在本地使用,您应该使用此声明:

npx nodemon name

0
投票

当您从终端运行

nodemon -v
时,它会尝试将其解析为 shell 命令,因为
nodemon
未全局安装。要执行此操作:

npm install -g nodemon

运行不带

npm install
npm i
(或
-g
)会将包安装在项目的本地目录中,这意味着
nodemon
位于项目的
node_modules
内,要使用本地安装,请将
nodemon
添加为package.json 中的脚本之一,例如:

{
  "name": "sof-express",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start:dev": "nodemon"
 

然后使用

npm run SCRIPT_NAME
运行它,如我的示例所示:
npm run start:dev

此外,由于

nodemon
是您“可以/应该”仅在开发/本地环境中使用的依赖项,因此您应该使用
-D
--save-dev
标志将其安装为 devDepdency:

npm i -D nodemon

将其添加到

devDependencies

{
  "name": "sof-express",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start:dev": "nodemon"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }
}

要使用

nodemon
运行我的开发服务器,我将执行:

npm run start:dev

0
投票

如果您已经全局安装了nodemon依赖项,并且上述命令都无法运行您的主node.js项目文件(node app.js或node server.js)。尝试使用“npm start”运行您的项目。


0
投票

您好,请参阅下面的链接来解决您的nodemon在vs code中无法启动的问题 简单来说 1-powershell 2-获取执行策略 3-设置执行策略不受限制 4-点击 y

你还可以看到这个 https://www.youtube.com/watch?v=8MBPDG6XDfE&ab_channel=TechnoED

© www.soinside.com 2019 - 2024. All rights reserved.