🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

envify

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
e

envify

Selectively replace Node-style environment variables with plain strings.

4.1.0
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

81

Maintenance

100

License

Version published
Weekly downloads
580K
-13.08%
Maintainers
3
Weekly downloads
 
Created
Issues
19

What is envify?

The envify npm package is a tool that allows you to replace environment variables in your JavaScript code with their corresponding values at build time. This is particularly useful for client-side applications where you want to inject environment-specific configurations without exposing sensitive information.

What are envify's main functionalities?

Basic Environment Variable Replacement

This feature allows you to replace environment variables in your JavaScript code with their actual values. In this example, the NODE_ENV variable is replaced with 'production' during the build process.

const envify = require('envify');
const browserify = require('browserify');

browserify('./main.js')
  .transform(envify({ NODE_ENV: 'production' }))
  .bundle()
  .pipe(process.stdout);

Using with Gulp

This feature demonstrates how to use envify with Gulp, a popular task runner. The environment variable NODE_ENV is replaced with 'production' during the build process, and the resulting bundle is saved to the './dist' directory.

const gulp = require('gulp');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const envify = require('envify/custom');

gulp.task('build', function () {
  return browserify('./main.js')
    .transform(envify({ NODE_ENV: 'production' }))
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('./dist'));
});

Using with Grunt

This feature shows how to use envify with Grunt, another popular task runner. The environment variable NODE_ENV is replaced with 'production' during the build process, and the resulting bundle is saved to the 'dist' directory.

module.exports = function(grunt) {
  grunt.initConfig({
    browserify: {
      dist: {
        files: {
          'dist/bundle.js': ['main.js']
        },
        options: {
          transform: [['envify', { NODE_ENV: 'production' }]]
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-browserify');
  grunt.registerTask('default', ['browserify']);
};

Other packages similar to envify

FAQs

Package last updated on 07 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts