Coder Social home page Coder Social logo

pherval / node-environment Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 588 KB

Inspect NODE_ENV environment variable. Query for well known environment values

Home Page: https://www.npmjs.com/node-environment

License: MIT License

JavaScript 100.00%
node-env node-environment nodejs javascript typescript

node-environment's Introduction

Code Style Publish to NPM

node-environment

Inspect or return the environment variable NODE_ENV

Requirements

node >=12

Features

  • Consult NODE_ENV known values (dev, development, production, prod)
  • Give development as default value
  • Return the raw value from NODE_ENV
  • All queries are case-insensitive

Installation

Install node-environment with npm

  npm install node-environment

Usage/Examples

Using CommonJS modules

const { env } = require('node-environment')

Using ECMAScript modules

import { env } from 'node-environment'
process.env.NODE_ENV = 'dev'

env('development') // true
env('staging', 'development') // true
env('test', 'production') // false
env() // "dev"

API Reference

The package only expose one function:

  env(): string
  env(query: string, ...otherEnvironments: string[]): boolean

Aliases:

prod == production

dev == development

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

License

MIT

node-environment's People

Contributors

peterleiva avatar

Stargazers

 avatar

node-environment's Issues

Programmatically setting environment

Sometimes maybe useful to set the environment programmatically, instead of relying on NODE_ENV it can be set using the API.

The API can add another function which set an environment according to any given string. An alias for common operations can be useful as well. Example:

env.set("development")
env.setDev()
env.set("prod")
env.setProd()

Add helper for common queries

There's case which I have to query for common environment all the time, having to typing env("<environment>") can be cumbersome.

Add utility function as an alias to common environment query
Example:
env("development") can have env.isDev, the same can be applied to env.isProd and so on.

That utilities can be functions or simple values without needing to calling a function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.