0.3.2 • Published 3 months ago

normal-env v0.3.2

Weekly downloads
-
License
APACHE
Repository
-
Last release
3 months ago

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

0.3.0

3 months ago

0.3.2

3 months ago

0.3.1

3 months ago

0.2.0

1 year ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago