Is there a way to set what the node_env is when building a nest app with nx?
What do you mean exactly? Building a nestjs app as production you would use
nx run nestjsapp:build:production
are you trying to set the environment variable NODE_ENV and build time instead of runtime?
when I run
yarn nx build api -c develop the compiled bundle has
process.env.NODE_ENV replaced with
I am using NODE_ENV in some places to check if its a dev server but I very well could just be using that env var wrong.
You should use the build in environments for that
You have an environment.ts and an environemnt.prod.ts
interesting I would not have expected the build to set
Got it, ya this code is very old (comparatively to the age of the company) and was originally migrated from a non monorepo, was also my first nest app ever so I am just ysing it wrong. I actually rewrote how our env vars are being used (to correctly following the environment file pattern) the other day, just havent merged them in yet,
in a meeting so short message, but check this out https://webpack.js.org/configuration/optimization/#optimizationnodeenv
i ran into that and solved it with a custom webpack config