Reputation: 1855
I failed to connected MongoDB with server and the codes are given below, please concern below,
app.js:
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(express.json());
module.exports = app;
.env:
MONGODB_SERVER = mongodb://localhost:27017/burger-builder
PORT = 3001
server.js:
const dotenv = require('dotenv');
dotenv.config();
const app = require('./app');
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_SERVER, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(() => console.log('Connect to MongoDB!'))
.catch(err => console.log('MongoDB Connection Failed!'));
const port = process.env.PORT || 3001;
app.listen(port, () =>{
console.log(`Listening on port ${port}`);
})
Please concern the attached file for checking the error.
Note: In .env
file I connected with the location as burger builder
but there is no any file . Is it the main probel to failed the MongoDB with the server?
Upvotes: 0
Views: 56
Reputation: 58
Upvotes: 1