// set the way we will connect to the server
const pgConnectionConfigs = {
user: '<MY_UNIX_USERNAME>',
database: '<MY_UNIX_USERNAME>',
port: 5432, // Postgres server always runs on this port
// create the var we'll use
const client = new Client(pgConnectionConfigs);
// make the connection to the server
const recipeQuery = 'SELECT * from recipes WHERE id=1';
client.query(recipeQuery, (recipeQueryError, recipeQueryResult) => {
// this error is anything that goes wrong with the query
console.error('recipe query error', recipeQueryError);
console.log(recipeQueryResult.rows);
// return early if no results
if (recipeQueryResult.rows.length <= 0) {
console.log('no results!');
// extract the recipe that we queried for
const recipe = recipeQueryResult.rows[0];
// MAGIC: use the result of the 1st query in the 2nd
const categoryQuery = `SELECT * FROM categories WHERE id=${recipe.category_id}`;
client.query(categoryQuery, (categoryQueryError, categoryQueryResult) => {
// this error is anything that goes wrong with the query
if (categoryQueryError) {
console.error('category query error', categoryQueryError);
console.log(categoryQueryResult.rows);