Hello,
I have a problem trying to connect to mongoDb ( using mongoose). It all worked untill today but nothing is changed.
First i thought that there is a problem with my code, but after checking the connection it shows that the problem is there.
This is the index.js:
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const helmet = require("helmet");
const morgan = require("morgan");
const userRoute = require("./routes/users");
const authRoute = require("./routes/auth");
const postRoute = require("./routes/posts");
dotenv.config();
mongoose.connect(
process.env.MONGO_URL,
{useNewUrlParser:true})
.then(()=>{
console.log("Connected to MongoDB");
})
.catch(()=>{
console.log("Couldn't connect to MongoDB");
})
//middleware
app.use(express.json());
app.use(helmet());
app.use(morgan('common'));
app.use("/api/auth", authRoute);
app.use("/api/users", userRoute);
app.use("/api/posts", postRoute);
app.listen(8800,()=>{
console.log("Backend server is running!")
})