TypeError: 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;
Anyone can help?
2
Answers
I think this line
should be
You need to change the line of
to
See: https://www.freecodecamp.org/news/module-exports-how-to-export-in-node-js-and-javascript/