I'm using the dotenv
library, but my env variables returns undefined
Here is app.ts
:
require('dotenv').config({path: '/.env'});
console.log(process.env.MAIN_DB_PATH) // returns undefined
Here is my .env
file:
MAIN_DB_PATH=./data/database.db
UPLOAD_MULTER_DIR=./module/car/uploads
My folder structure is
So it should works fine :(
You do not need path if the .env
file is at the root, but you can define a return value from config method and check if error happend
const result = dotenv.config()
if (result.error) {
throw result.error
}
console.log(result.parsed)
source: https://www.npmjs.com/package/dotenv config paragraph
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With