Comments (3)
我更新了connect-mongo这个库
import express from "express";
import db from "./mongodb/db.js";
import config from "config-lite";
import router from "./routes/index.js";
import cookieParser from "cookie-parser";
import session from "express-session";
import connectMongo from "connect-mongo";
import winston from "winston";
import expressWinston from "express-winston";
import history from "connect-history-api-fallback";
import chalk from "chalk";
// import Statistic from './middlewares/statistic'
const app = express();
app.all("*", (req, res, next) => {
const { origin, Origin, referer, Referer } = req.headers;
const allowOrigin = origin || Origin || referer || Referer || "*";
res.header("Access-Control-Allow-Origin", allowOrigin);
res.header(
"Access-Control-Allow-Headers",
"Content-Type, Authorization, X-Requested-With"
);
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", true); //可以带cookies
res.header("X-Powered-By", "Express");
if (req.method == "OPTIONS") {
res.sendStatus(200);
} else {
next();
}
});
// app.use(Statistic.apiRecord)
// const MongoStore = connectMongo(session);
app.use(cookieParser());
app.use(
session({
name: config.session.name,
secret: config.session.secret,
resave: true,
saveUninitialized: false,
cookie: config.session.cookie,
store: connectMongo.create({
mongoUrl: config.url,
}),
})
);
// app.use(expressWinston.logger({
// transports: [
// new (winston.transports.Console)({
// json: true,
// colorize: true
// }),
// new winston.transports.File({
// filename: 'logs/success.log'
// })
// ]
// }));
router(app);
// app.use(expressWinston.errorLogger({
// transports: [
// new winston.transports.Console({
// json: true,
// colorize: true
// }),
// new winston.transports.File({
// filename: 'logs/error.log'
// })
// ]
// }));
app.use(history());
app.use(express.static("./public"));
app.listen(config.port, () => {
console.log(chalk.green(`成功监听端口:${config.port}`));
});
可以试试更新以上的库这样后行不。
不行的话。还可以更新这两个库
"mongodb": "^6.6.1",
"mongoose": "^8.3.4" (这个更新后会说findOne已经不知回调了,改成promise)的写法就可以了
我现在可以成功启动了
from node-elm.
我也遇到了同样的问题,node版本是18.x。我看到对应的mongodb包的版本是6.x,我升级之后还是不行。感觉是项目中的mongodb版本太老了,已经不支持OP_QUERY command的一些指令了,但是具体怎么解决呢?
from node-elm.
from node-elm.
Related Issues (20)
- 如何修改地图类api接口为自己的腾讯地图接口 HOT 2
- 接口用不了了
- 你好,接口用不了了 HOT 1
- stack Error: Could not find any Python installation to use 报错 HOT 1
- 崩溃了
- node-elm HOT 1
- 用户名密码验证码 登入时出错
- 大佬 ,接口用不了了,可以修复一下吗 HOT 1
- 填写完用户名 密码 验证码 登陆失败,但是用postman测试就成功是为什么啊
- 项目启动时报mongodb错误,请问下是什么原因 HOT 3
- MongoDB配置简易教程 HOT 2
- elm的搜索餐馆接口出了问题
- elm的搜索地址接口出了问题 HOT 3
- 接口挂了,是服务器崩了吗,该咋办啊
- 关于接口报错的解决办法
- bailicandu /
- 接口蹦了,能整一下吗亲!
- 后端程序报错,接口504 HOT 1
- 搜索地址接口出问题了,能不能修复一下 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-elm.