Actually you have define the path of the .env file
Try like this
import * as dotenv from "dotenv";
dotenv.config({ path: __dirname+'/.env' });
Try this also
require('dotenv').config({ path: __dirname+'/.env' });
Change the path of .env file as required
reference : https://github.com/motdotla/dotenv#options