问题描述
我在 glitch.com 上开始了一个新项目,并在 .env 中添加了一个变量和值
明文显示:
SECRET=beNice
(无引号)
console.log(process.env.SECRET)
显示:
流程未定义
如何调用这些变量?
https://glitch.com/edit/#!/important-chambray-liquid
解决方法
环境变量只能在应用程序的服务器端访问,而不能在客户端访问,因为您的静态站点当前正在尝试这样做。
以服务器端代码访问环境的应用为例,您可以在 the Glitch node app starter 中看到它正在访问 PORT 变量。