Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
ReferenceError: users is not defined when trying to connect to postgres

i have been following this video https://www.youtube.com/watch?v=ufdHsFClAk0 and in 32:54 when the guy got the result i got an error ReferenceError: users is not defined. here is my code so far

const {Client} = require('pg')
const users = [{ id: 1 }] 
const client = new Client({
    user: "postgres",
    password: "testing",
    host: "BlackPearl",
    port: 5432,
    database: users
})

execute()

async function execute(){
    await client.connect()
    console.log("Connected")
    const results = await client.query("select * from users")
    console.table(results.rows)
    await client.end()
    console.log("Disconnected")
}

and here is what i see in pgAdmin4

that's my package.json

{
  "name": "expr",
  "version": "1.0.0",
  "description": "",
  "main": "experiment.js",
  "scripts": {
    "test": "node experiment.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pg": "^8.7.1"
  }
}

in the terminal i write npm run test

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

change this:

const client = new Client({
    user: "postgres",
    password: "testing",
    host: "BlackPearl",
    port: 5432,
    database: users
})

to this:

const client = new Client({
    user: "postgres",
    password: "testing",
    host: "BlackPearl",
    port: 5432,
    database: 'users'
})

database name should be a string, not a reference, if it's called differently (not users) use the proper name

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!