I am probably over engin…

1 minute read

I am probably over-engineering this, but how do you organize your variables inside your environment.ts? Do you prefer data structures over strings or follow the node env style? Nodes env var are just strings.

Responses:

https://gist.github.com/beeman/4c99f5c506d8025efc07640470c25aae

This is something I’ve been using in some of my projects. It works pretty well.

It’s simple, straightforward and predictable, it’s all in one file

For my latest project I’m doing it differently, using @nestjs/config . You can see an example here:

https://github.com/beeman/nx-nest-graphql/blob/master/libs/core/src/lib/core.module.ts#L12-L16

The latter is a bit more work to set up but I think it’s cleaner. It also has proper validation.

I didnt know about nestjs/config. I will start using it. I used dotenv before. Glad nestjs wraps dotenv.

I dont know how familiar you are with angular. Angular has an environment.ts and environment.prod.ts. It gets swapped when built. I was thinking I could use these files to store all my global variables. I think it will work, the only issue is when I decide to add a react or web app. Maybe I could store all of my variables in a single ts file, platform agnostic, and my angular environment.ts file could import this first file. That way I could reuse the same config variables in multiple projects. But this is way down the road. It could live in angular for now.

There have been quite a few threads here in <#CMFKWPU6Q support> recently about doing dynamic environment.ts with several solutions

Updated: