Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
dotenv-local
Advanced tools
A utility library for loading local environment variables with prioritized file loading in Node.js and Vite projects. Extends dotenv functionality for better environment management in various modes like development, production, and testing.
dotenv-local
is a utility library for loading environment variables with a specific order of priority, ideal for managing configurations in different environments such as development, production, and testing.
npm install dotenv-local
# or
yarn add dotenv-local
LoadEnvOpts
typeexport type LoadEnvOpts = {
envDir?: string;
mode?: "development" | "production" | "testing" | "staging" | string;
envPrefix?: string | string[];
envInitial?: Record<string, string>;
removeEnvPrefix?: boolean;
encoding?: string;
};
import { loadEnv, LoadEnvOpts } from "dotenv-local";
const opts: LoadEnvOpts = {
envDir: "/path/to/env/files",
mode: "production",
envPrefix: ["APP_"],
envInitial: {
DEFAULT_VAR: "default_value",
},
removeEnvPrefix: false,
encoding: "utf-8",
};
const envVariables = loadEnv(opts);
console.log(envVariables);
process.cwd()
).process.env.NODE_ENV || "production"
.'APP_'
.{}
.false
.'utf-8'
.const {
mode = process.env.NODE_ENV || "production",
envDir = process.cwd(),
envPrefix = "APP_",
envInitial = {},
removeEnvPrefix = false,
encoding = "utf-8",
} = opts;
getEnvFilesForMode
The library determines the order of environment file loading based on the provided mode (e.g., mode = development).
[".env", ".env.local", ".env.development", ".env.development.local"];
This array represents the priority order in which environment files will be loaded. Files with later positions in the array will override those defined earlier.
import { loadEnv } from "dotenv-local";
const envVariables = loadEnv();
console.log(envVariables);
import { loadEnv } from "dotenv-local";
const customOptions = {
envDir: "/path/to/custom/env/files",
mode: "staging",
envPrefix: ["API_", "MONGO_"],
envInitial: {
INITIAL_VAR: "initial_value",
},
removeEnvPrefix: true,
encoding: "utf-16",
};
const envVariables = loadEnv(customOptions);
console.log(envVariables);
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A utility library for loading local environment variables with prioritized file loading in Node.js and Vite projects. Extends dotenv functionality for better environment management in various modes like development, production, and testing.
We found that dotenv-local demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.