jamesgeer / conf-twitter-bot

A Twitter Bot to post about academic papers
MIT License
4 stars 0 forks source link

Export environment (.env) variables from a single "keys" file #23

Closed jamesgeer closed 2 years ago

jamesgeer commented 2 years ago

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;

some-file.ts

import { someKey } from './keys'