简体   繁体   English

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

[英]How do I access .env variable using Glitch?

I start a new project on glitch.com, and add a variable and value in.env我在 glitch.com 上开始一个新项目,并在.env 中添加一个变量和值

Plaintext shows: SECRET=beNice (no quotes)明文显示: SECRET=beNice (无引号)

console.log(process.env.SECRET) shows: process is not defined console.log(process.env.SECRET)显示:未定义进程

How can I call these variables?如何调用这些变量?

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

Environment variables can only be accessed on the server side of an app, not on the client side as your static site linked there currently is trying to do.环境变量只能在应用程序的服务器端访问,而不是在客户端,因为您的 static 站点当前正在尝试执行此操作。

For an example of an app with server side code accessing the environment, you can see in the Glitch node app starter that it's accessing the PORT variable.对于具有服务器端代码访问环境的应用程序示例,您可以在Glitch 节点应用程序启动器中看到它正在访问 PORT 变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM