这个表达如何工作? “ require(dotenv”)。
我看到了此表达式:
require('dotenv').config();
在nodejs项目中server.js
文件的开头。我只是想知道它是如何工作的,它做什么?
因为几乎总是我在需要
表达行之类的
const express = require('express');
之后
const app = express();
都看到了一个变量。而且它没有像通用方法那样使用。
I saw this expression:
require('dotenv').config();
At the beginning of a server.js
file within a NodeJS project. I am just curious to know how does it work and what does it do?
Because almost always I have seen a variable before the require
expression line like
const express = require('express');
and afterwards it will be used somehow like
const app = express();
But require('dotenv').config();
looks different and it hasn't been used like the common approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导入类型
require()
不能在类型模块
和import
中使用 在类型commonjs
示例包 .json设置导入类型后,这是两种类型的
“ dotenv”
中这两种类型的示例,这是读取
.env
文件的环境变量模块。 方法是导入它
以下
的两种
.js
file'express'
的两种方法。
这是用
commonjs
或module
Import Types
Example package.json
after setting the import type here are the examples of both types in action
'dotenv'
This is the environment variables module to read
.env
files. Below are the two ways to import it whether you're using typecommonJS
ormodule
works like this...
.env file
then in a
.js
file'express'
this is the two ways to import express with either
commonJS
ormodule
CommonJS vs ES Module