File: esm.mdx

package info (click to toggle)
node-postgres 8.16.3%2B~cs35.24.27-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,788 kB
  • sloc: javascript: 15,879; python: 79; makefile: 57
file content (37 lines) | stat: -rw-r--r-- 940 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
title: ESM
---

## ESM Support

As of v8.15.x node-postgres supporters the __ECMAScript Module__ (ESM) format. This means you can use `import` statements instead of `require` or `import pg from 'pg'`.

CommonJS modules are still supported. The ESM format is an opt-in feature and will not affect existing codebases that use CommonJS.

The docs have been changed to show ESM usage, but in a CommonJS context you can still use the same code, you just need to change the import format.

If you're using CommonJS, you can use the following code to import the `pg` module:

```js
  const pg = require('pg')
  const { Client } = pg
  // etc...
```

### ESM Usage

If you're using ESM, you can use the following code to import the `pg` module:

```js
  import { Client } from 'pg'
  // etc...
```


Previously if you were using ESM you would have to use the following code:

```js
  import pg from 'pg'
  const { Client } = pg
  // etc...
```