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

dotenv-load

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-load

Load environment variables from .env, .env.local, .env.production, etc. when running a npm or yarn command

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.7K
decreased by-16%
Maintainers
1
Weekly downloads
 
Created
Source

dotenv-load code style: prettier

Load environment variables from .env, .env.local, .env.production, etc. when running a npm or yarn command.

This dotenv loading behaviour was extracted from create-react-app to be also usable with non create-react-app projects like next.js or any other node specific project.

Usage

Use in yarn or npm commands

dotenv-load can be used in an yarn/npm command:

{
  "scripts": {
    "dev": "dotenv-load node server.js",
    "build": "NODE_ENV=production dotenv-load node server.js"
  }
}

Use in node script

dotenv-load can be used in an yarn/npm command:

const dotenvLoad = require('dotenv-load');
dotenvLoad();

ignore .local files

add .local files to .gitignore

.env.local
.env.development.local
.env.production.local

What other .env* files can I use?

dotenv-load will load the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence:

  • .env - The Original®
  • .env.local - Local overrides. This file is loaded for all environments except test.
  • .env.development, .env.test, .env.production - Environment-specific settings.
  • .env.development.local, .env.test.local, .env.production.local - Local overrides of environment-specific settings.

How can I use custom env file?

You can pass a string to dotenvLoad function, but your file should have a name like .env.YOUR_CUSTOM_NAME, for example: .env.default.

Then you can initialize it as follows:

dotenvLoad() # will initialize standard names
dotenvLoad('default') # will initialize your `.env.default` (while not overwriting defined vars above)

Keywords

FAQs

Package last updated on 02 Aug 2023

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