# node-env-type

> NodeJS Environment Type detection.

Latest version **0.0.8** (published 2020-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-env-type
pnpm add node-env-type
yarn add node-env-type
bun add node-env-type
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2020-10-09 |
| First published | 2020-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vitaly Tomilov |
| Maintainers | vitaly.tomilov |
| Keywords | node, nodejs, environment, type, detection |

## Links

- npm: https://www.npmjs.com/package/node-env-type
- Repository: https://github.com/vitaly-t/node-env-type
- Issues: https://github.com/vitaly-t/node-env-type/issues
- npm.io page: https://npm.io/package/node-env-type

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.0.8 (latest) — 2020-10-09
- 0.0.7 — 2020-10-09
- 0.0.6 — 2020-10-08
- 0.0.5 — 2020-10-08
- 0.0.4 — 2020-10-08
- 0.0.3 — 2020-10-08
- 0.0.2 — 2020-10-08
- 0.0.1 — 2020-10-08

## README

# node-env-type

Easy detection of NodeJS environment type from `NODE_ENV` variable.

This library is 100% compatible with the standard `development`/`test`/`production` approach,
with a friendlier interface, while also supporting a more verbose syntax, to allow for
a flexible environment configuration.

## Installing

```
$ npm i node-env-type
```

## Usage

* In TypeScript:

```ts
import {env} from 'node-env-type';

if(env.isDev) {
 // this is a DEV environment
}
```

* In JavaScript:

```ts
const {env} = require('node-env-type');

if(env.isProd) {
 // this is a PROD environment
}
```

## Environment Flags

Table below explains available flags and when they are set.

| Flag     |      Environment           |  Condition |
|:--------:|:--------------------------:|:-----------|
| `isDev`  | Development                | `NODE_ENV` includes `dev` (case-insensitive) |
| `isUAT`  | User Acceptance Testing    | `NODE_ENV` includes `uat` (case-insensitive) |
| `isSIT`  | System Integration Testing | `NODE_ENV` includes `sit` (case-insensitive) |
| `isCI`   | Continuous Integration     | `NODE_ENV` includes `ci` (case-insensitive)  |
| `isTest` | General Testing            | `NODE_ENV` includes any of: `test`, `tst`, `uat`, `sit`, `ci` (case-insensitive)|
| `isProd` | Production                 | `NODE_ENV` includes `prod` (case-insensitive), or not set at all. |

Flags are tested in the order as shown in the table, to use only the first one found, in case there's a conflict.

#### Special Cases

* `isTest` - set not only when `NODE_ENV` includes `test` or `tst`, but also when `isUAT`, `isSIT` or `isCI`
  is set, because all those environments are essentially for testing.
* `isProd` - set not only when `NODE_ENV` includes `prod`, but also when `NODE_ENV` is not set at all,
  i.e. when environment is not configured, we should assume it to be production.
* When `NODE_ENV` is set to something we cannot recognize at all, each flag is set to `false`.    

## API

The only API available other than the environment flags is function `refresh`, in case you want
to refresh flags from the environment without restarting the process.

```ts
import {env} from 'node-env-type';

if(env.refresh()) {
    // successfully recognized the environment;
    // each flag updated from NODE_ENV
} else {
    // failed to recognize the environment;
    // each flag is set to false
} 
```

And if, for some reasons, you decide to read configuration from a different place, rather than
the standard `NODE_ENV`, you can pass such optional string to the function:

```ts
const otherVar = 'dev1.pc'; // just some other value

if(env.refresh(otherVar)) {
    // successfully recognized the environment;
    // each flag updated from otherVar
} else {
    // failed to recognize the environment;
    // each flag is set to false
} 
```

---
_Source: https://npm.io/package/node-env-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
