mongodb TypeError:connectToMongo不是函数

wfypjpf4  于 2023-06-29  发布在  Go
关注(0)|答案(2)|浏览(125)

类型错误:connectToMongo不是函数

  • 我的代码(Index.js)*
const connectToMongo = require('./db')
connectToMongo();
  • 我的代码(db.js)*
const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost:27017"

const connectToMongo = ()=> {
    mongoose.connect(mongoURI,()=>{
        console.log("Connected to mongo successfully")
    })
}

module.export = connectToMongo;

任何人都可以帮助?

pgvzfuti

pgvzfuti1#

我觉得这条线

module.export = connectToMongo;

应该是

module.exports = connectToMongo;
evrscar2

evrscar22#

你需要改变

module.export = connectToMongo;

module.exports = connectToMongo;

参见:https://www.freecodecamp.org/news/module-exports-how-to-export-in-node-js-and-javascript/

相关问题