我正在学习pdf课程-Shama Hoque的full-stack-react-projects
。在其他解决该问题的方法中,我使用命令行全局更新了npm和node,但仍然收到此错误消息-throw new TypeError('"listener" argument must be a function');
您可以在此处找到代码-https://github.com/Shittu1/mern-skeleton。我的server.js文件如下:
import config from './../config/config';
import app from './express';
import mongoose from 'mongoose';
mongoose.Promise = global.Promise;
mongoose.connect(config.mongoUri);
mongoose.connection.on('error', { useNewUrlParser: true }, () => {
throw new error(`Unable to connect to the database ${mongoUri}`);
})
app.listen(config.port, (err) => {
if(err){
console.log(err);
}
console.info('Server started on port: ', config.port)
})
[请,我需要有人帮助我。谢谢。
我看不到错误处理程序在哪里使用了处理程序功能以外的参数,您是否尝试过根据文档进行设置?
mongoose.connection.on('error', err => {
throw new error(`Unable to connect to the database ${config.mongoUri}`);
})
附带说明,在您的代码中,未定义mongoUri,您的意思是config.mongoUri吗?
文档来自https://mongoosejs.com/docs/connections.html
要在建立初始连接后处理错误,您应该监听连接上的错误事件。但是,您仍然需要如上所示处理初始连接错误。
mongoose.connection.on('error', err => { logError(err); });