Questions tagged [node-postgres]

Node-postgres is a postgresql client module for node.js applications to interact with postgresql databases.

About

Node-postgres is a postgresql client module for node.js applications to interact with postgresql databases.

Its source code and wiki can be found on GitHub.

587 questions
14
votes
1 answer

Using Async/Await with node-postgres

I am using node-postgres to query my database and would like to know how to use async/await and handle errors correctly An example of my use is here with a very simple query const { Pool } = require('pg'); let config; if (process.env.NODE_ENV ===…
Richlewis
  • 15,070
  • 37
  • 122
  • 283
14
votes
5 answers

Insert POINT into postgres database

I need to insert/update a point column type in postgres database. I'm using node-postgres The script generated using POSTGRES admin panel shows the update query as UPDATE public.places SET id=?, user_id=?, business_name=?, alternate_name=?,…
Deepak Bandi
  • 1,854
  • 4
  • 21
  • 37
13
votes
4 answers

Proper insertion of table name

How does one correctly provide the table name if the name can be dynamically determined and still prevent SQL injection attacks? I am using node-postgres. For example: The following works but I believe is insecure: dbclient.query("INSERT INTO " +…
H W
  • 153
  • 1
  • 7
13
votes
3 answers

Node-postgres Inserting a new record into my database does not return the new entry's data

Here's the route from which the query is being executed: userRouter.route("/new") .post(function (req, res) { var user = req.body; pg.connect(connectionString, function (error, client, done) { var queryString =…
Michael P.
  • 1,373
  • 3
  • 12
  • 33
13
votes
2 answers

ECONNREFUSED when making GET request in app, but API returns JSON successfully

I'm writing a node app with React, using node-postgres and superagent for backend calls. Let's say I'm making a GET request and using the JSON it returns to fill a table of students. My API looks like this: import pg from 'pg'; import Router from…
johnprisco
  • 143
  • 1
  • 1
  • 7
12
votes
1 answer

Error: connect ECONNREFUSED 127.0.0.1:5432 when connecting with nodejs program

I have a postgresql server set up on a CentOS 8 machine, and a js program running on the same machine, using the pg library. const { Pool } = require('pg') const pool = new Pool({ user: process.env.PG_USER, //postgres user host:…
K. Sutherland
  • 196
  • 1
  • 1
  • 9
12
votes
10 answers

node-postgres, Connection terminated unexpectedly

I'm trying to connect to a remote database using node-postgres. I can connect using the psql client, but I get the error Connection terminated unexpectedly while trying to run this (with same connection string as in psql client): const { Pool,…
John Jeromin
  • 121
  • 1
  • 1
  • 5
12
votes
2 answers

node-postgres transactions with callbacks or async/await?

I'm running Node 7.6.0, which supports async/await. The node-postgres client pool supports async/await, and has a nice example here. However, the example for transactions in node-postgres (here) uses callbacks instead of async/await. Despite that…
Rob Johansen
  • 5,076
  • 10
  • 40
  • 72
12
votes
7 answers

Error Relation does not exist

I am getting a [error: relation "causes" does not exist] error from my node app. The relation does exist, I'm not sure what the problem is. I created the table with CREATE TABLE causes ( cause_id bigint NOT NULL default…
Kinnard Hockenhull
  • 2,790
  • 5
  • 27
  • 34
11
votes
2 answers

Date type displaying with timezone on node-postgres module

I have stored input data in date format in postgres database, but when I am showing the date in browser it's showing date with timezone and converting it from utc. For example I have stored the date in 2020-07-16 format. But when i am showing the…
Pho
  • 193
  • 1
  • 9
11
votes
1 answer

using postgres with nodejs for connection pool

i am using nodejs as my REST api host. The overall functionality is pretty basic. that is, make a REST call which should do a postgres db query and return data. The problem I am having is the overall code organization. I have the server.js which…
Vik
  • 8,721
  • 27
  • 83
  • 168
11
votes
4 answers

webpack import error with node-postgres ('pg'.Client)

Trying to bundle the following file with Webpack fails with ERROR in ./~/pg/lib/native/index.js Module not found: Error: Cannot resolve module 'pg-native' in .../node_modules/pg/lib/native @ ./~/pg/lib/native/index.js 9:13-33 I tried…
Rentrop
  • 20,979
  • 10
  • 72
  • 100
11
votes
5 answers

How to make a synchronous query (blocking call) with node-postgres?

While booting my Node.js app, I want to make a couple of synchronous calls to the PostgreSQL database to check some things before continuing the control flow. How can I achieve this using the node-postgres package?
Dejan
  • 9,150
  • 8
  • 69
  • 117
11
votes
1 answer

How do I use node-postgres in a server?

I'm writing a Node.js web server that uses a Postgres database. I used to connect on each new request like this: app.get('/', function (req, res) { pg.connect(pgconnstring, function (err, client) { // ... }); }); But after a few requests, I…
alltom
  • 3,162
  • 4
  • 31
  • 47
11
votes
1 answer

Storing a file in postgres using node-postgres

I'm trying to store a small file into a postgres db using the node-postgres module. I understand that I should use the bytea data type to do this. The problem I'm having is when I do some thing like: fs.readFile path, (err, data) -> client.query…
Clive
  • 405
  • 2
  • 5
  • 12
1
2
3
39 40