[ .env ] in nodejs

src/configs/env.js

import dotenv from 'dotenv'
import path from 'path'
// set up environment
dotenv.config({ path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV}`) })

src/server.js

import './configs/env'

run

NODE_ENV=development nodemon ./src/server.js --exec babel-node

ref : https://medium.freecodecamp.org/heres-how-you-can-actually-use-node-environment-variables-8fdf98f53a0a

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s