Having to use the following code to use environment variables is a little tedious and causes problems when files are moved due to needing a relative path to the .env file and means there is no IntelliSense.
import * as dotenv from 'dotenv';
dotenv.config({ path: '../../.env' });
const someKey = process.env.SOME_KEY;
There should be a single "keys.ts" file that exports all of these env variables, then the code will just be like so:
keys.ts
import * as dotenv from 'dotenv';
dotenv.config({ path: '../.env' });
export const someKey = process.env.SOME_KEY;
export const anotherKey = process.env.ANOTHER_KEY;
Having to use the following code to use environment variables is a little tedious and causes problems when files are moved due to needing a relative path to the .env file and means there is no IntelliSense.
There should be a single "keys.ts" file that exports all of these env variables, then the code will just be like so:
keys.ts
some-file.ts