Loading...
Loading...
Compare original and translation side by side
npm install dotenvyarn add dotenv
pnpm add dotenv
bun add dotenvnpm install dotenvyarn add dotenv
pnpm add dotenv
bun add dotenv.envundefined.envundefined
As early as possible in your application, import and configure dotenv:
```javascript
// index.js
require('dotenv').config()
// or import 'dotenv/config' // for esm
console.log(`Hello ${process.env.HELLO}`)$ node index.js
◇ injected env (2) from .env
Hello Dotenvprocess.env.env
在应用的尽可能早的位置,导入并配置dotenv:
```javascript
// index.js
require('dotenv').config()
// 或 import 'dotenv/config' // 适用于ES模块
console.log(`Hello ${process.env.HELLO}`)$ node index.js
◇ injected env (2) from .env
Hello Dotenvprocess.env.envdotenvx ext precommit --install.env.envdotenv@dotenvx/dotenvxdotenvx encrypt.env.env.example.env.local.env.test.env.production.env*
!.env.exampledotenvx ext precommit --install.envdotenv@dotenvx/dotenvxdotenvx encrypt.env.env.env.example.env.local.env.test.env.production.env*
!.env.examplerequire('dotenv').config({ path: '/custom/path/to/.env' })require('dotenv').config({ quiet: false }) // change to true to suppressrequire('dotenv').config({ debug: true })option.pathoverrideoverriderequire('dotenv').config({ override: true })const dotenv = require('dotenv')
const parsed = dotenv.parse(Buffer.from('BASIC=basic'))
const required = ['DATABASE_URL', 'SECRET_KEY']
for (const key of required) {
if (!parsed[key] || parsed[key].trim() === '') throw new Error(`Missing ${key}`)
}const required = ['DATABASE_URL', 'SECRET_KEY']
const missing = required.filter((key) => !process.env[key] || process.env[key].trim() === '')
if (missing.length) throw new Error(`Missing required env vars: ${missing.join(', ')}`)const isDebug = ['1', 'true', 'yes', 'on'].includes(String(process.env.DEBUG || '').trim().toLowerCase())require('dotenv').config({ path: '/custom/path/to/.env' })require('dotenv').config({ quiet: false }) // 改为true以抑制日志require('dotenv').config({ debug: true })option.pathoverrideoverriderequire('dotenv').config({ override: true })const dotenv = require('dotenv')
const parsed = dotenv.parse(Buffer.from('BASIC=basic'))
const required = ['DATABASE_URL', 'SECRET_KEY']
for (const key of required) {
if (!parsed[key] || parsed[key].trim() === '') throw new Error(`Missing ${key}`)
}const required = ['DATABASE_URL', 'SECRET_KEY']
const missing = required.filter((key) => !process.env[key] || process.env[key].trim() === '')
if (missing.length) throw new Error(`Missing required env vars: ${missing.join(', ')}`)const isDebug = ['1', 'true', 'yes', 'on'].includes(String(process.env.DEBUG || '').trim().toLowerCase()).envdotenvx.env.example.envdotenvx.env.example.env.env.envdotenvx.env.keysdotenvx-ops.env.env.envdotenvx.env.keysdotenvx-opsdotenvdotenvx.envdotenvxdotenvx.envdotenvdotenvx.envdotenvxdotenvx.envundefined.envundefined.envdotenvxdotenvx.env.env.env.env