Skip to content

Docs: Getting Started: Wrap await code in async IIFE #1629

@anishkny

Description

@anishkny

Before:

const { Client } = require('pg')
const client = new Client()

await client.connect()

const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()

After:

const { Client } = require('pg')
const client = new Client()

(async () => {
  await client.connect()
  
  const res = await client.query('SELECT $1::text as message', ['Hello world!'])
  console.log(res.rows[0].message) // Hello world!
  await client.end()
})();

Meta: Are the docs open sourced? Do you accept fixes from the community?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions