WRITING THE CODE
Start with the connection.js file
Inside the db folder create a file called connection.js
and add the following code to it
const mongoose = require('mongoose');
require('dotenv').config();
const connection = async () => {
try {
await mongoose.connect(process.env.MONGO_URI)
console.log('Successfully connected to Database...');
} catch (error) {
console.log(error);
}
}
connection();
YOU CAN NOW RUN THE connection.js FILE IN THE TERMINAL
AND IT SHOULD SHOW THE FOLLOWING
Successfully connected to Database...
in the terminal
If it does go on to create the server, if it doesn't check all previous steps
NOW CREATE THE SERVER