
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
load-dotenv
Advanced tools
Automatically find the closest .env file in any parent directory of the cwd, and then load those environment variables into process.env.
By default the dotenv package only looks in the current working directory of the Node.js process for a .env file. And if you use the path option, that path must be identical both when running locally and when running in production.
Monorepos are a common example when it may be convenient to have a .env file that is not in your cwd. load-dotenv allows you to have a single .env file used by every package, regardless of file structure.
load-dotenv provides a simple interface to load your environment variables, only requiring you to add a single import statement. That avoids the hassle of wanting to load your environment vars before any other code runs, but also having to place all the imports at the top of your file before any other code.
Make sure you also install dotenv, which is a peer dependency of this package.
npm i dotenv load-dotenv # With npm
pnpm i dotenv load-dotenv # With pnpm
yarn add dotenv load-dotenv # With yarn
As early as possible in your application, import load-dotenv/load:
import 'load-dotenv/load'
Or in Common JS:
require('load-dotenv/load')
This will by default throw an error if it can't find a
.envfile in any parent directory. To not throw an error, importload-dotenv/load/optionalinstead.
import {findEnv} from 'load-dotenv'
import * as dotenv from 'dotenv'
const envFilePath = findEnv()
dotenv.config({path: envFilePath})
Or in Common JS:
const {findEnv} = require('load-dotenv')
const dotEnv = require('dotenv')
const envFilePath = findEnv()
dotEnv.config({path: envFilePath})
Or with a custom name:
const envFilePath = findEnv('.env.local')
dotenv.config({path: envFilePath})
FAQs
Automatically load the closest .env file
The npm package load-dotenv receives a total of 189 weekly downloads. As such, load-dotenv popularity was classified as not popular.
We found that load-dotenv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.