javascriptenvironment-variablesglitch-framework

How do I access .env variable using Glitch?


I start a new project on glitch.com, and add a variable and value in .env

Plaintext shows: SECRET=beNice (no quotes)

console.log(process.env.SECRET) shows: process is not defined

How can I call these variables?

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


Solution

  • 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.

    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.