Giter Club home page Giter Club logo

envify's Introduction

envify Build Status stable

Selectively replace Node-style environment variables with plain strings. Available as a standalone CLI tool and a Browserify v2 transform.

Works best in combination with uglifyify.

Installation

If you're using the module with Browserify:

npm install envify browserify

Or, for the CLI:

sudo npm install -g envify

Usage

envify will replace your environment variable checks with ordinary strings - only the variables you use will be included, so you don't have to worry about, say, AWS_SECRET_KEY leaking through either. Take this example script:

if (process.env.NODE_ENV === "development") {
  console.log('development only')
}

After running it through envify with NODE_ENV set to production, you'll get this:

if ("production" === "development") {
  console.log('development only')
}

By running this through a good minifier (e.g. UglifyJS2), the above code would be stripped out completely.

CLI Usage

With browserify:

browserify index.js -t envify > bundle.js

Or standalone:

envify index.js > bundle.js

You can also specify additional custom environment variables using browserify's subarg syntax, which is available in versions 3.25.0 and above:

browserify index.js -t [ envify --NODE_ENV development ] > bundle.js
browserify index.js -t [ envify --NODE_ENV production  ] > bundle.js

Module Usage

require('envify')

Returns a transform stream that updates based on the Node process' process.env object.

require('envify/custom')([environment])

If you want to stay away from your environment variables, you can supply your own object to use in its place:

var browserify = require('browserify')
  , envify = require('envify/custom')
  , fs = require('fs')

var b = browserify('main.js')
  , output = fs.createWriteStream('bundle.js')

b.transform(envify({
  NODE_ENV: 'development'
}))
b.bundle().pipe(output)

Contributors

envify's People

Contributors

hughsk avatar benjamn avatar andreypopp avatar bjoerge avatar jupl avatar pgherveou avatar zag2art avatar

Watchers

James Cloos avatar  avatar

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.