nodemon 服务器命令不工作——我的第一个全栈 mern 环境

nodemon server command not working - my first full stack mern environment

我正在关注 this guide,我在需要 运行 此代码的部分:

$ nodemon server

但是我得到这个错误:

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 + ~~~~~~~ + CategoryInfo : ObjectNotFound: (nodemon:String) [], CommandNotFoundExce
ption + FullyQualifiedErrorId : CommandNotFoundException

我更改了 package.json 中的一些设置并全局安装了 npm,但如果需要我会再试一次。

这是我的 server.js 文件:

const express = require('express');
const cors = require('cors');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());

app.listen(port, () => {
    console.log(`Server is running on port: ${port}`);
});

我在错误之前安装了 nodemon,我在安装 nodemon 时得到了这个输出。

PS C:\Users\username\mern-excercise-tracker\backend> npm install -g nodemon C:\Users\username\AppData\Roaming\npm\nodemon -> C:\Users\username\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js

nodemon@1.19.3 postinstall C:\Users\username\AppData\Roaming\npm\node_modules\nodemon node bin/postinstall || exit 0

npm 警告可选跳过可选依赖项:fsevents@1.2.9 (node_modules\nodemon\node_modules\fsevents):
npm WARN notsup 跳过可选依赖项:fsevents@1.2.9 不受支持的平台:需要 {"os":"darwin","arch":"any"}(当前:{"os":"win32","arch":"x64"})

看看这个Answer这可能会给你更多的见解。

除此之外,还有一种解决方法是使用 npx

npx nodemon server.js

您需要 npm@5.2.0 或更高版本。你可以通过以下方式检查你的 npm 版本 npm -v 在 CMD