🔧 Selectively replace Node-style environment variables with plain strings.
Installations
npm install envify
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
6.4.0
NPM Version
5.0.4
Score
96.8
Supply Chain
99.4
Quality
80.4
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
hughsk
Download Statistics
Total Downloads
197,857,060
Last Day
20,705
Last Week
127,270
Last Month
1,255,300
Last Year
20,013,252
GitHub Statistics
902 Stars
68 Commits
57 Forks
12 Watching
1 Branches
12 Contributors
Bundle Size
133.97 kB
Minified
29.90 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.1.0
Package Id
envify@4.1.0
Size
3.09 kB
NPM Version
5.0.4
Node Version
6.4.0
Publised On
07 Jul 2017
Total Downloads
Cumulative downloads
Total Downloads
197,857,060
Last day
-17.1%
20,705
Compared to previous day
Last week
-53.6%
127,270
Compared to previous week
Last month
-47.5%
1,255,300
Compared to previous month
Last year
-16.2%
20,013,252
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
envify
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:
1npm install envify browserify
Or, for the CLI:
1sudo 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:
1if (process.env.NODE_ENV === "development") { 2 console.log('development only') 3}
After running it through envify with NODE_ENV
set to production
, you'll
get this:
1if ("production" === "development") { 2 console.log('development only') 3}
By running this through a good minifier (e.g. UglifyJS2), the above code would be stripped out completely.
However, if you bundled the same script with NODE_ENV
set to development
:
1if ("development" === "development") { 2 console.log('development only') 3}
The if
statement will evaluate to true
, so the code won't be removed.
CLI Usage
With browserify:
1browserify index.js -t envify > bundle.js
Or standalone:
1envify 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:
1browserify index.js -t [ envify --NODE_ENV development ] > bundle.js 2browserify 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:
1var browserify = require('browserify') 2 , envify = require('envify/custom') 3 , fs = require('fs') 4 5var b = browserify('main.js') 6 , output = fs.createWriteStream('bundle.js') 7 8b.transform(envify({ 9 NODE_ENV: 'development' 10})) 11b.bundle().pipe(output)
Purging process.env
By default, environment variables that are not defined will be left untouched. This is because in some cases, you might want to run an envify transform over your source more than once, and removing these values would make that impossible.
However, if any references to process.env
are remaining after transforming
your source with envify, browserify will automatically insert its shim for
Node's process object, which will increase the size of your bundle. This weighs
in at around 2KB, so if you're trying to be conservative with your bundle size
you can "purge" these remaining variables such that any missing ones are simply
replaced with undefined.
To do so through the command-line, simply use the subarg syntax and include
purge
after envify
, e.g.:
1browserify index.js -t [ envify purge --NODE_ENV development ]
Or if you're using the module API, you can pass _: "purge"
into your
arguments like so:
1b.transform(envify({ 2 _: 'purge' 3 , NODE_ENV: 'development' 4}))
Contributors
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 8/27 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
2.9
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to envify
loose-envify
Fast (and loose) selective `process.env` replacer using js-tokens instead of an AST
@types/envify
TypeScript definitions for envify
@goto-bus-stop/envify
Selectively replace Node-style environment variables with plain strings.
@browserify/envify
Selectively replace Node-style environment variables with plain strings.