javascript - 在控制器 NestJS 中的对象内获取 .env 变量
问题描述
我创建了 .env
APP_PORT=3001
DEST=C:\data\formations
我在控制器承包商中有 configService:ConfigService。我想DEST
在这段代码中从 .env 获取目的地。
@UseInterceptors(FileInterceptor('file', {
storage: diskStorage({
destination: /*here*/ ,
filename: (req, file, cb) => {
const filename: string = path.parse(file.originalname).name.replace(/\s/g, '')
const extension: string = path.parse(file.originalname).ext
cb(null, `${filename}${extension}`)
}
})
}))
当我在这个其他对象中使用它时,我得到一个错误。
解决方案
您应该使用ConfigModule
获取环境变量。
推荐阅读
- python-3.x - 如何将列表字符串转换为时间戳
- python - 均值居中后方差不变的高斯过程
- python - 从python评估“带有shell变量的Shell命令行”或将python字符串评估为shell命令行
- .net - 有没有办法创建一个无控制台的 dotnet 核心应用程序?
- c# - 等待从数据库加载数据时调用 Workbook_SheetChange()
- javascript - 只能调用一次的函数
- css - 将图像和文本与 flex 容器项中的类对齐
- c# - 在 C# 中工作的正则表达式在 MSBuild 中不起作用
- reactjs - 在 Gatsby-React 类组件中使用 Graphql 获取数据
- java - ZonedDateTime序列化差异与不同服务器上相同的代码和相同的依赖关系