xxxxxxxxxx
//in your script file
import 'dotenv/config';
//alertnatively you can do this when you env file is not in your main folder
import dotenv from 'dotenv';
import path from 'path';
dotenv.config({path: './config/.env'});
//or
dotenv.config({path: path.resolve(__dirname, 'config/.env')});
xxxxxxxxxx
# file: .env
SECRET_KEY=secret_token_here
# filename: test.py
"""
create a file in local directory
touch .env
add entries with following format:
SECRET_KEY=secret_token_here
"""
from dotenv import load_dotenv
import os
# By Default below line will load a file ".env" in current working directory
load_dotenv(".env")
secret_key = os.getenv('SECRET_KEY')
print(secret_key)
# output:
> python .\test_env.py
secret_token_here