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