Environment variables are useful for feeding your application information from outside the running of that application. It is typically used to set things like database connection details and API keys.

Environment variables for your application.
Environment variables for your application.

Adding Environment Variables

To add environment variables, go to your application’s Settings page, scroll down to the Environment variables section, and click the Add environment variable button. Add the key-value pairs in the Add environment variable modal/pop-up window.

Add an environment variable key-value pair.
Add an environment variable key-value pair.

Using Environment Variables

How you use environment variables is up to your application. In Node, for example, you can access a variable named API_KEY with process.env.API_KEY. In PHP, you would use getenv('API_KEY').

Environment Variables Set By Kinsta

Kinsta always sets PORT as the port used by the web server. If you’d like your application to interact with the web server, you will need to use this environment variable. For example, in Node, this is how you would start a server:

app.listen(process.env.PORT, () => {
console.log("Weather server is up and running")