'MONGO_USER' 不是内部或外部命令,也不是可运行的程序或批处理文件

'MONGO_USER' is not recognized as an internal or external command, operable program or batch file

我正在关注 Udemy 上的 NodeJS 教程 尝试此代码时出现错误

{
  "name": "nodejs-complete-guide",
  "version": "1.0.0",
  "description": "Complete Node.js Guide",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "MONGO_USER=MonkeyKing MONGO_PASSWORD=loveguitar4ever MONGO_DEFAULT_DATABASE=message STRIPE_KEY=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 node app.js",
    "start-server": "node app.js",
    "start:dev": "nodemon app.js"
  },
  "author": "MonkeyKing",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^1.18.3"
  },
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "connect-flash": "^0.1.1",
    "connect-mongodb-session": "^2.0.3",
    "csurf": "^1.9.0",
    "ejs": "^2.6.1",
    "express": "^4.16.3",
    "express-handlebars": "^3.0.0",
    "express-session": "^1.15.6",
    "express-validator": "^5.3.0",
    "mongodb": "^3.1.6",
    "mongoose": "^5.2.17",
    "multer": "^1.4.0",
    "mysql2": "^1.6.1",
    "nodemailer": "^4.6.8",
    "nodemailer-sendgrid-transport": "^0.2.0",
    "pdfkit": "^0.8.3",
    "pug": "^2.0.3",
    "sequelize": "^5.0.0-beta.11",
    "stripe": "^6.12.1"
  }
}

错误是:

'MONGO_USER' is not recognized as an internal or external command,
operable program or batch file.
sk_live_51GekpQCukpHeumjmDZhZiXzC5F6SaltbPDxQGLPE9sswmFWknSZL87m1a7ktjnpm ERR!
npm ERR! Failed at the nodejs-complete-guide@1.0.0 start script.      GO_PASSWORD=loveguitar4ever MONGO_DE
npm ERR! This is probably not a problem with npm. There is likely addiSaltbPDxQGLPE9sswmFWknSZL87m1a7ktjImtional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\MonkeyKing\AppData\Roaming\npm-cache\_logs20-07-19T01_23_24_946Z-debug.log     

运行 您的代码来自类 UNIX shell,而不是来自 Windows' cmd.execmd 无法理解为命令添加变量赋值前缀的语法。

以Git Bash为例。我假设您已经安装了 Git(如果没有,我敢打赌您很快就会安装)。

为了获得更多 Linux-y 环境,我建议首先使用 WSL (Windows Subsystem for Linux) 进行 Web 开发。

对于这种特定情况:您还可以从 start 脚本中删除变量赋值,并在启动应用程序之前手动 运行 它们,使用 set MONGO_USER=MonkeyKing 等,并记住做每次你打开一个新的 shell (可能创建一个批处理文件)。或者将其移动到 .env 文件中并使用 dotenv 包加载它。