question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PG Pool connect using `await` error : Unexpected identifier

See original GitHub issue

According to doc https://node-postgres.com/features/connecting

const Koa = require('koa')
const app = new Koa()

const { Pool } = require('pg')

const pool = new Pool({connectionString:"postgresql://shawn:passwordxxxxxx@localhost:5432/dbname"})

const res = await pool.query('SELECT NOW()')
await pool.end()

await client.end()

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Error Log

Debugging with inspector protocol because Node.js v8.6.0 was detected.
node --inspect-brk=25673 BE/app.js 
Debugger listening on ws://127.0.0.1:25673/60ee7dd1-9214-474b-b475-5f1e1a660e87
Debugger attached.
/Users/shawn/todayinhistory/BE/app.js:9
const res = await pool.query('SELECT NOW()')
                  ^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3
Waiting for the debugger to disconnect...
SyntaxError: Unexpected identifier
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
iShawnWangcommented, Oct 30, 2017

So the doc is outdated !

2reactions
AllanOcelotcommented, Jul 27, 2018

Hi all, this is still an issue (Outdated docs) - as someone picking up postgress tonight and trying to follow along with the docs, I’m still left scratching my head here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

await with pg throws an error - node.js - Stack Overflow
The node.js complains with the error: await pool.connect() ^^^^ SyntaxError: Unexpected identifier at ...
Read more >
node-mssql | Microsoft SQL Server client for Node.js
An important concept to understand when using this library is Connection Pooling as this library uses connection pooling extensively. As one Node JS...
Read more >
Node.js with MySQL - w3resource
Pooling connections, options and events; Escaping query values, identifiers; Preparing Queries; Stored procedures; Joins; Transactions; Timeouts ...
Read more >
Pooling – node-postgres
node-postgres ships with built-in connection pooling via the pg-pool module. ... pool.on('error', (err, client) => { console.error('Unexpected error on idle ...
Read more >
Reactive PostgreSQL Client - Eclipse Vert.x
Most of the time you will use a pool to connect to PostgreSQL: ... SqlClient client = PgPool.client(vertx, connectOptions, poolOptions); // Pipelined ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found