I currently have a node.js application where I have a require('dotenv').config();
line that I only want to run when the application is in development, and not production mode.
To achieve this, I want to set a NODE_ENV environment variable to 'development' locally (and set to 'production' when on AWS), and I'll have an set of conditional statements like:
if (process.env.NODE_ENV == "development") {
require('dotenv').config();
}
I cannot set this NODE_ENV variable in my .env file, as then accessing that would require the require('dotenv').config();
line which will only run depending on whether the if statement evaluates to true. I have tried to set the value of NODE_ENV through set NODE_ENV=development
in the terminal in vscode, but it didn't work so I had to do it on command prompt, where it did work (confirmed by typing the command set and seeing NODE_ENV=development), but now when I try to access it through process.env.NODE_ENV, its value is undefined - anyone know the correct procedures to set/access NODE_ENV?