normal-env
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

Normal Env Normal Env

npm version install size

This project aimed to cover base requirements in work with NODE_ENV environment variable and it equivalent in the other platforms with convenient interface.

Installation:

With npm:

$ npm i normal-env --save-prod ( --save-dev )

With yarn:

$ yarn add normal-env [ --dev ]

Usage

/* file: db-cursor.ks */

import { Env } from 'normal-env';

const env = new Env();
const config = fs.readFileSync(`db.${env}.json`).toString();
const connection = db.createConnection({
  ...config,
  debug: env.isDevelopment()
})
/* file: webpack.config.js */

import { Env } from 'normal-env';

const env = new Env();

export default {
  mode: env.toWebpackMode(),
  devtool: env.isDevelopment()
    ? 'cheap-module-source-map'
    : null,
  optimization: env.isDevelopment()
    ? {
      minimize: true,
      minimizer: [new TerserPlugin()]
    }
    : null
  // ... rest of webpack configuration
};

What happined here?

  • We import named class "Env" (not default exported). It will take data from your environment based on your system (web, node.js, deno or bun);
  • Make an instance of this class;
  • It can serialize to string so we put it in filename to read. (check config keys in this file to find possible variations);
  • We put config to abstract database client connection method and extends it with debug property and check is environment in development as a value;

How it work from terminal?

$ node ./server.js

will set environment to default value "development"

$ set NODE_ENV=tst
$ node -r "normal-env" -p "new Env().toString()"
> test

will set environment to "test" value

$ set NODE_ENV=prod
$ node -r "normal-env" -p "new Env().toString()"
> production

will set environment to "production" value

$ set NODE_ENV=ci
$ node -r "normal-env" -p "new Env().toString()"
> ci

will set environment to "ci" value

Readme

Keywords

Package Sidebar

Install

npm i normal-env

Weekly Downloads

1

Version

0.3.2

License

APACHE

Unpacked Size

28.1 kB

Total Files

11

Last publish

Collaborators

  • astanin