Set variables
Environment variables belong to one application. They survive restarts and commits, but a new upload creates a new application without them, so set them again there.- Dashboard
- CLI
- VS Code
- API
- Open your application in the dashboard and go to Settings → Environment Variables.
- Add each key and value, or import an existing
.envfile. - Click Save. The dashboard asks whether to restart the application: restart it so the app picks up the new values.
Read them in your code
Variables Square Cloud sets for you
Your application starts with these variables already defined:
Because
NODE_ENV is production, npm install skips devDependencies. If your START command builds the project (for example with typescript or vite), list those build tools under dependencies in package.json.
How variables reach your app
Square Cloud injects the variables every time the application starts, before dependencies are installed and yourSTART command or MAIN file runs. Two consequences:
- Names use letters, digits, underscores, dots and hyphens, and don’t start with a digit.
- Values with spaces or special characters such as
$,&,;or|are stored single-quoted for you, so they arrive exactly as typed. In the dashboard and withsquarecloud app env set, a$is kept literal; to build a value from another variable with the CLI, see Manage environment variables from the CLI. Through the VS Code extension and the API, a plain reference to another variable ($HOSTor${HOST}) stays live and is expanded at start: to keep a$literal there, as in a password likep@ss$Word, send the value in single quotes ('p@ss$Word'). A value you quote yourself is kept as sent.
STATIC_APP_ENV_NOT_SUPPORTED.
Keep secrets out of your upload
If your code loads a.env file itself (for example with dotenv), that file has to be in the upload. Listing .env in squarecloud.ignore then starts the app without its secrets, and a bot fails with an invalid token.
The safer setup: move each value from your .env into the application’s environment variables, as shown above. Once they are set, you can leave .env out of the upload and out of your Git repository. dotenv doesn’t overwrite variables that already exist, so the same code keeps working on your machine and on Square Cloud.
Next steps
Configuration file
Set
MAIN, MEMORY, START and the other fields of squarecloud.app.Host a Discord bot
Deploy a bot that reads its token from an environment variable.
Discord bot errors
Fix an invalid token, missing intents and bots that go offline.
Database connection errors
Connect with a
DATABASE_URL and the right SSL settings.
