search

Home  >  Q&A  >  body text

TypeError: connectToMongo is not a function

Type error: connectToMongo is not a function

My code (Index.js)

const connectToMongo = require('./db')
connectToMongo();

My code (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;

Can anyone help?

P粉428986744P粉428986744493 days ago761

reply all(1)I'll reply

  • P粉344355715

    P粉3443557152023-09-16 14:28:02

    I think this line

    module.export = connectToMongo;

    should be

    module.exports = connectToMongo;

    reply
    0
  • Cancelreply