Using AWS CDK with dotenv -r and TypeScript

Note, I prefer the node --require option of loading .env variables over importing or requiring in application code. TLDR; install dotenv as a development dependency in the cdk.json in the root of the project directory add the following in bold : { "app": "npx ts-node -r dotenv/config --prefer-ts-exts bin/<stack-name>.ts" } When developing via AWS CDK it is easy to set environment …

Preload dotenv, don’t require it

Oh my dotenv! If you work with NodeJS at some point you will use and implement dotenv. It loads environment variables from a .env file (configurable name btw), into process.env, following the 12 Factor App methodology of separating environment from code. Pure awesomeness, and makes development configuration loading a breeze mimicking your higher environments.