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 stores the variables in a.squarecloud/.env file inside the application and loads them with a shell every time the application starts, before dependencies are installed and your START command or MAIN file runs. Two consequences:
- Names should use letters, digits and underscores, and not start with a digit.
- Values with spaces or shell characters such as
$,&,;or|must be quoted, or the shell cuts or expands them. The dashboard andsquarecloud app env setquote them for you. In the VS Code extension or the API, wrap such a value in single quotes yourself: type'p@ss word$1', or send"PASSWORD": "'p@ss word$1'"in the API body.
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.
