Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-env-file

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-env-file

Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.

  • 0.1.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.8K
decreased by-32.78%
Maintainers
1
Weekly downloads
 
Created
Source

NODE-ENV-FILE Build Status

Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. process.env.

Example

.env

  # some env variables

  FOO=foo1
  BAR=bar1
  BAZ=1
  QUX=
  # QUUX=

.env2

  # some env variables using exports syntax

  exports FOO=foo2
  exports BAR=bar2
  exports BAZ=2
  exports QUX=
  # exports QUUX=

index.js

  var assert = require('assert');
  var env = require('node-env-file');

  process.env.FOO = "defaultfoo";

  // Load any undefined ENV variables form a specified file.
  env(__dirname + '/.env');
  assert.equal(process.env.FOO, "defaultfoo");
  assert.equal(process.env.BAR, "bar1");
  assert.equal(process.env.BAZ, "1");
  assert.equal(process.env.QUX, "");
  assert.equal(process.env.QUUX, undefined);

  // Load another ENV file - and overwrite any defined ENV variables.
  env(__dirname + '/.env2', {overwrite: true});
  assert.equal(process.env.FOO, "foo2");
  assert.equal(process.env.BAR, "bar2");
  assert.equal(process.env.BAZ, "2");
  assert.equal(process.env.QUX, "");
  assert.equal(process.env.QUUX, undefined);

API

  • (filepath)

    env('./path/to/.env');
    
  • (filepath, options)

    env('./path/to/.env', {verbose: true, overwrite: true, raise: false, logger: console});
    

Installation

  $ npm install node-env-file

Test

Local tests:

  $ make test

Examples

Local examples:

  $ make example

License

Released under the MIT license.

Copyright (c) Jonas Grimfelt

Bitdeli Badge

Keywords

FAQs

Package last updated on 18 Feb 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc