0.1.0 • Published 4 years ago

@teqm/nodejs-env-utils v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@teqm/nodejs-env-utils

npm install @teqm/nodejs-env-utils

or

yarn add @teqm/nodejs-env-utils

Getting started

import Environment from '@teqm/nodejs-env-utils';

const databaseUrl = Environment.get('DATABASE_URL', 'mysql://user@localhost:3306');

const port = Environment.getInt('APP_PORT', 8080);

const debug = Environment.getBoolean('DEBUG', false);

TypeScript

Create file in your project root directory e.g. process.d.ts with contents:

// process.d.ts
declare namespace NodeJS {
  export interface ProcessEnv {
    NODE_ENV: 'development' | 'production';
    DATABASE_URL?: string;
    APP_PORT?: string;
    DEBUG?: string;
  }
}

and include it in your TypeScript configuration file:

// tsconfig.json
{
  // ...
  "include": ["process.d.ts"]
}