Full NestJS Starter Kit — Part 3 Environment Variables

Andrew Larsen
4 min readDec 30, 2023

In this series of articles we’re walking through how to create a NestJS starter kit to use for your cloud applications. In our previous article we walked through how to configure Authentication and Authorization in our starter kit.

In this article we’ll setup our application to use environment variables.

Environment Configuration

A common practice in our cloud application deployments is to change certain behavior based on what environment the app is running in. For example selecting which database configuration to fetch from a secret, turning feature flags on or off (if we’re not using a tool for that), third party service credentials, etc.

While NestJS recommends leveraging its module system to manage these variables via environment files (.env), we prefer leveraging process-level environment variables. We generally don’t want to mess with files during our deployment process, which is why we rely on these process variables. However, we do still use their module system as, if nothing else, it makes stubbing values far easier in testing.

If you want to understand more how NestJS recommends using their environment module with .env files, you can read more in their docs

--

--

Andrew Larsen
Andrew Larsen

No responses yet