New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dotenv-force

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-force

dotenv 默认不会覆盖系统原有的环境变量,该包为强制版本,可以覆盖原有系统变量。 内部代码非常简单,只有以下几行:

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
8
14.29%
Maintainers
1
Weekly downloads
 
Created
Source

dotenv 默认不会覆盖系统原有的环境变量,该包为强制版本,可以覆盖原有系统变量。
内部代码非常简单,只有以下几行:

const dotenv = require("dotenv");
const fs = require("fs");
const path = require("path");

let envFile = fs.readFileSync(path.join(process.cwd(), ".env"));
let env = dotenv.parse(envFile);

for (let k in env) {
  process.env[k] = env[k];
}

使用方法:

  • 在根目录创建.env文件
DEBUG=true
  • 直接引用即可(无需调用.config()方法)
require("dotenv-force");
console.log(process.env.DEBUG); //true

Keywords

dotenv

FAQs

Package last updated on 23 Jun 2020

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