【发布时间】:2021-01-23 00:17:13
【问题描述】:
我知道dotenv模块与nodejs中的环境变量有关
require("dotenv").config();
我知道我应该把这段代码放在我的 nodejs 服务器文件中。 但问题是我不明白 config 方法实际上在做什么?
export interface DotenvConfigOptions {
path?: string;
encoding?: string;
debug?: boolean;
}
export interface DotenvConfigOutput {
error?: Error;
parsed?: DotenvParseOutput;
}
/**
* Loads `.env` file contents into {@link https://nodejs.org/api/process.html#process_process_env | `process.env`}.
* Example: 'KEY=value' becomes { parsed: { KEY: 'value' } }
*
* @param options - controls behavior
* @returns an object with a `parsed` key if successful or `error` key if an error occurred
*
*/
export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
/** @deprecated since v7.0.0 Use config instead. */
export const load: typeof config;
我查看了配置函数,但我无法理解这段代码的作用?
【问题讨论】:
标签: javascript node.js dotenv