I have been writing most of my APIs in old-school JavaScript using const var = require('var').
I am now writing my first API in ES6 syntax including using import rather than require. I always use the node-postgres module const {Pool} = require('pg')
but when I try to write this as import {Pool} from 'pg'
I get the error
SyntaxError: The requested module 'pg' does not provide an export named 'Pool'.
Similarly, import Pool from 'pg'
gives me
TypeError: Pool is not a constructor
Is there a way to import this as an ES6 module or do I need to find another package for my ES6 postgres connections? I couldn't find any examples online of people using node-postgres with imports.
This should handle that I think.
import * as pg from 'pg'
const { Pool } = pg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With