Step 5: Configure environment variables 

Up until now, we’ve installed our tooling—but all of our configurations have been hardcoded. But, what if we have some configuration to use in our application? Let’s update the db.js file in the repo to use environment variables set with Gitpod.

You can set environment variables inside a workspace using gp env (from the Workspace CLI). To see currently set environment variables, run gp env:

language icon bash
gp env

Let’s use gp env to set our environment variables:

language icon bash
eval $(gp env -e USER=gitpod)
eval $(gp env -e DATABASE=eventhub_db)

And reference the variables in our db.js file by updating it to:

language icon javascript
const { Pool } = require('pg');

const pool = new Pool({
	user: process.env.USER,
	host: 'localhost',
	database: process.env.DATABASE,
	password: '',
	port: 5432,
});

module.exports = pool;

Next Steps

What next? →

Was this helpful?