javascript - 在 node js 服务器的终端中无法识别 nodemon 命令

标签 javascript node.js nodemon

我正在从 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

enter image description here

node server.js 命令正在运行并启动了服务器,但是 nodemon 命令不起作用。

我从 https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens 设置 Node 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

我看过一个链接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

如果使用 yarn ,则可选

# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve

npm 会先查看本地 node_modules 文件夹,然后再在全局模块中查找命令

关于javascript - 在 node js 服务器的终端中无法识别 nodemon 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40359590/

相关文章:

typescript - 有没有办法使用 npm 脚本来运行 tsc -watch && nodemon --watch?

javascript - ...scrollTop($(这个)...)

用于创建 Svelte 元素而不是模板的 JavaScript API

javascript - onBeforeUnload 事件来创建这个?

javascript - 如何根据div标签图像自动调整图像大小

node.js - 尝试在 Mathjax-node 中使用 "useFontCache: false"

node.js - 有人在制作 Node 优化的 V8 吗?

javascript - 变量未定义 node.js

node.js - Nodemon 不使用 --ignore 选项

node.js - 更改 hbs 文件时服务器重新启动