Deadpool
Deadpool

Reputation: 8240

Express, Node Error - connectDB is not a Function

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:

enter image description here

Upvotes: 0

Views: 423

Answers (1)

dave
dave

Reputation: 64657

You need to change

module.export = connectDB;

to

module.exports = connectDB;

Upvotes: 4

Related Questions