Languages
[Edit]
EN

Node.js - how to connect with PostgreSQL

0 points
Created by:
Brett4
465

In this article, we would like to show you how to use PostgreSQL in Node.js.

Step 1 - Install the node-postgres module in your Node project. 

Step 2 - Import the pg module by using require and create a connection with the PostgreSQL database. 

That's it, you've been connected and from now on you can query your database.

Practical example with SELECT query: 

Edit
  • with async/await
  • with promises

References: 

Edit
  1. pg package - npm

Alternative titles

  1. Node.js - how to install PostgreSQL
  2. How to use PostgreSQL in Node
  3. Node.js - install PostgreSQL Driver
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join