当我尝试执行
npm run app
时,我收到以下语法错误。
$ npm run app
> [email protected] app
> nodemon app.js
[nodemon] 3.0.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node app.js`
/home/harsh/Documents/GDSCMernClass/node_modules/mongodb/lib/error.js:714
return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/harsh/Documents/GDSCMernClass/node_modules/mongodb/lib/operations/add_user.js:5:17)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
[nodemon] app crashed - waiting for file changes before starting...
./config/db.js 的内容
const mongoose = require('mongoose');
const config = require('config')
const db = config.get('mongoURI')
const connectDB = async () => {
try {
mongoose.set('strictQuery', true);
await mongoose.connect(db, {
useNewUrlParser: true,
});
console.log('MongoDB Connected');
}
catch (err){
console.error(err.message);
process.exit(1);
}
};
module.exports = connectDB;
App.js的内容
const express = require('express');
const connectDB = require('./config/db')
const app = express();
connectDB();
app.get('/', (req, res) => res.send("Hello world"))
const port = process.env.PORT || 8082
app.listen(port, () => console.log(`Server running on port ${port}`));
package.json的内容
{
"name": "gdscmernclass",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"app": "nodemon app.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Harsh-raj/GDSCMernclass.git"
},
"author": "Harsh Raj",
"license": "MIT",
"bugs": {
"url": "https://github.com/Harsh-raj/GDSCMernclass/issues"
},
"homepage": "https://github.com/Harsh-raj/GDSCMernclass#readme",
"dependencies": {
"body-parser": "^1.20.2",
"config": "^3.3.9",
"express": "^4.18.2",
"mongoose": "^7.5.0",
"n": "^9.1.0"
},
"devDependencies": {
"nodemon": "^3.0.1"
}
}
./config/default.json 包含 mongoURI,我正确地输入了密码。请帮我纠正这个错误。非常感谢。
我试图运行 Node 应用程序,一切都设置得很好,但我收到了命令的语法错误
npm run app
返回 RETRYABLE_WRITE_ERROR_CODES.has( (错误.结果 && 错误.结果.代码) ||错误代码 || 0 );