I am trying to set the test database for the testing purpose, but its not working.
I am trying to connect to mongodb using mongoose, but finding problem in connection er
In the server directory,
npm install dotenv
In your server.js: If you use "type":"module" in your package.json file then,
import dotenv from 'dotenv';
import mongoose from 'mongoose';
dotenv.config();
or,
const mongoose = require('mongoose')
require('dotenv').config()
Add a .env file in the server directory,
PORT=5000
MONGO_URL= yourURL
In the server.js,
const url = process.env.MONGO_URL
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => app.listen(PORT, () => console.log("Server up and running!")
.catch((error) => console.log(error.message)
mongoose.set('useFindAndModify', false)