I think you miss importing env file.
env
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.
{ useNewUrlParser: true }
mongoose.connect(config.DB,{ useNewUrlParser: true }));