Stack Overflow Asked on December 23, 2021
I am new to express and tyring to connect to mongoAtlas via Express and start the server. I am facing an error where I have no clue why is it coming. Can someone help me out?
db.js
const mongoose = require('mongoose');
const config = require('config');
const db = config.get('mongoURI');
const connectDB = async () => {
try {
await mongoose.connect(db);
console.log('MongoDB Connected...')
}
catch(err) {
console.log(err.message);
process.exit(1);
}
}
module.export = connectDB;
server.js
const express = require('express');
const connectDB = require('./config/db');
const app = express();
// Connect database
connectDB();
app.get('/', (req, res) => res.send('API Running...'));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
Error:
You need to change
module.export = connectDB;
to
module.exports = connectDB;
Answered by dave on December 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP