mongoose.connect(), first argument should be String, received undefined mongoose.connect(), first argument should be String, received undefined mongoose mongoose

mongoose.connect(), first argument should be String, received undefined


I think you miss importing env file.

require('dotenv').config({ path: 'ENV_FILENAME' });


To read from .env file you have to install dotenv ( npm i dotenv / yarn add dotenv)and then just add this on top of your file.

const dotenv = require("dotenv");dotenv.config();


I was also facing same problem after add code { useNewUrlParser: true } in mongoose.connect() method. Problem resolved.

mongoose.connect(config.DB,{ useNewUrlParser: true }));