如何使用 Glitch 访问 .env 变量?

问题描述

我在 glitch.com 上开始了一个新项目,并在 .env 中添加一个变量和值

明文显示SECRET=beNice (无引号)

console.log(process.env.SECRET) 显示: 流程未定义

如何调用这些变量?

https://glitch.com/edit/#!/important-chambray-liquid

解决方法

环境变量只能在应用程序的服务器端访问,而不能在客户端访问,因为您的静态站点当前正在尝试这样做。

以服务器端代码访问环境的应用为例,您可以在 the Glitch node app starter 中看到它正在访问 PORT 变量。