new

Try Stack Overflow for Business

Our new business plan for private Q&A; offers single sign-on and advanced features. Get started by May 31 for 2 months free.

Learn more

All Questions

1
vote
1answer
30 views

Can I import the node-postgres module (pg) or is it CommonJS only? [duplicate]

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 ...
0
votes
2answers
100 views

Async/await with function push not working [duplicate]

I have a problem with async - await. What is happening? I have a function of callback that a sends an array of objects, with valid objects and invalid objects to other function. In the function, I ...
0
votes
1answer
20 views

Javascript Conversion of LEFT OUTER JOIN Query Result

I am using node-postgres to retrieve the results of a LEFT OUTER join query: SELECT S.SEASON_ID, S.SEASON_NAME, I.ITEM_NAME, I.NOTE FROM T_SEASON S LEFT OUTER JOIN T_ITEM I ON S.SEASON_ID = I....
0
votes
2answers
288 views

How to do insert with array in SQL with JavaScript Node?

i have a problem. I have an array and i want that each element to be a row from column; Example: My Array: const myArray = ['A', 'B', 'C', 'D']; and result is: Column1 | --------------------------...
1
vote
1answer
38 views

Node Postgres Pub/Sub - remaining connection slots are reserved

I've built a notification system with node-postgres and socket.io. The system works alright, however, I am getting an error on startup. remaining connection slots are reserved for non-replication ...
-1
votes
1answer
34 views

Compare data within multiple queries - Postgres Node.js

So I am creating an API endpoint where I send in two different types of data from the UI. One is a string and the other is an array containing upto 5 items. I need to compare the results across the ...
0
votes
0answers
42 views

INSERT and DELETE of multiple records using node-postgres

What do you think about this INSERT and DELETE of multiple records using node-postgres. I guided myself a little with this thread: https://github.com/brianc/node-postgres/issues/957 but I'm not sure ...
0
votes
2answers
215 views

Why do I need to use async/await twice in node-postgres

I wrote this code that seems to be working: database.js const {Pool} = require('pg'); const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); module.exports = { query: (text, ...
0
votes
1answer
35 views

Trying to pass a Promise to another function that then returns it, getting “Unhandled promise rejection”

I want to create a generic database update function that I can use to implement more customized update functions. In a module database.js I have the following: const {Pool,Client}=require('pg'); ...
0
votes
1answer
29 views

Function to get rows from DB by multiple columns conditionally

So lets say I have a GET route for /movies (it's not actually movies but it would be easier to explain this way) On client side I have a table that I want to filter movies depending on dropdown menus:...
2
votes
3answers
2k views

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 ...
0
votes
1answer
316 views

Bundling node.js web API with webpack

I'm implementing a web API based on node.js. API can interact with a database. So I use node-postgres library for a data access layer. Now I need to configure webpack in the right manner in order to ...
0
votes
1answer
459 views

Node.js await postgresql error

I use express and PostgreSql. My Project Folder : -Model -Visitor.js -app.js I have connected postgresql with pg and i've tested with a query. It's running well. But, there is a query on ...
0
votes
2answers
1k views

Node.js node-postgres get JSON objects from API call

I have followed the node-postgres.org instruction at https://node-postgres.com/guides/async-express to connect via async/await to my postgres table users. Navigating to localhost:3000/users/1 will ...
1
vote
1answer
64 views

When using async await, how do you specify a callback?

I was looking at how to use transactions in: https://node-postgres.com/features/transactions But in the following code example: const { Pool } = require('pg') const pool = new Pool() (async () =&...
0
votes
1answer
852 views

node-postgres: [error] This socket has been ended by the other party

I use node-protgres to manipulate the db in my nodejs app. What I have done: const { Pool, Client } = require('pg') var dbconnect = { user: 'xxxxx', database: 'xxxxx', password: 'xxxxx', ...
12
votes
3answers
9k views

query.on is not a function

I am trying to learn how to use javascript to connect to a postgresql database but when I try to log a query to the console using query.on(...), I get a type error that says "query.on is not a ...
0
votes
1answer
352 views

Insert JSON Fails Node-Postgres

I am trying to insert an array of JSON into Postgres. Everything appears to run successfully (the table gets created), but there is no data inserted, and no error given. I am using the async/await ...
3
votes
2answers
79 views

How to save and return JavaScript Object with Subarray in Normalized SQL

I am using postgres-node, but I think this is a problem for anyone with javascript objects that have subarrays they want to save in SQL. I have a javascript objects with a varying amount (any-length) ...
0
votes
0answers
1k views

Nodejs Postgres Query with Call

I'm trying to use the recommendation of the creator of node-postgres and separate the database call as a separate file. This will enable both scaling and consolidation of the various, boilerplate ...
0
votes
4answers
114 views

How to return a result from a generator calling an asynchronous function?

I'm using the Koa framework and ES6. How do I get the first method to return a result to this view function that requires a yield? I am trying to use the pg library, which uses asynchronous calls, in ...
2
votes
1answer
2k views

How to set schema in pg-promise

I was searching the documentation of pg-promise specifically in the creation of the client. But I wasn't able to find the option to set the default schema to be used in the connection, it always uses ...
1
vote
1answer
494 views

How to end 'pg-promise' app

I am trying to write a REST API which based on the request payload picks a database and performs certain actions. As per the documentation, I am releasing the shared connection object at the end of ...
0
votes
0answers
1k views

Node-postgres parameterized queries with array parameter

I'm trying to execute this PSQL query to call a function and get a list of ids back. [This function works when run in PGAdmin as it should, verified by the ids coming back.] SELECT get_dataids( '...
0
votes
0answers
312 views

Promise based node-postgres request under Node.js

I'm trying to implement a promise-based approach to accessing a PostgreSQL database. This is the original code: // ./sql/config/pgQuery.js module.exports = (text, values, cb) => { pool.connect((...
0
votes
1answer
190 views

node-postgres: Update more than one record at once

I'm building an app in node.js using node-postgres. I don't know how to update more than one record at once. Here is my code: var status = 20; var id = [23,12,43]; pool.connect(function(err, client, ...
-1
votes
1answer
122 views

for loop inside query

I have this in mongo: //fill QueryString collection.find({"myID" : {$in:QueryString} },{}).toArray(function(err, Stuff) { ... var flag = true; for (var i=0; i<Stuff.length; i++) { //if ...
10
votes
3answers
9k views

How do I properly insert multiple rows into PG with node-postgres?

A single row can be inserted like this: client.query("insert into tableName (name, email) values ($1, $2) ", ['john', '[email protected]'], callBack) This approach automatically comments out any ...
4
votes
1answer
4k views

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, ...
0
votes
1answer
78 views

Why is my query working on pgAdming but when I execute it from the server I get a query error (Error: Connection Terminated)?

I'm working on my Capstone project and it requires to store some telemetry data on a database. I'm using PostgreSQL 9.5 for the database and node for the server. My problem is that when I try to ...
0
votes
1answer
46 views

First 'property' of node-postgres error object

Anybody know what the first pseudo-property is in my error object on a faulty query? When I console.log('' + error); it grabs the text within the brackets to display. Other than that, I'm not sure ...
7
votes
2answers
8k views

How to set right date format for editable-date

I getting some date fileds from postgres with format like: "2000-11-30T14:00:00.000Z" I can't use this in my editable-date field on page. Something like: <a href="#" editable-date="employee....
15
votes
2answers
20k views

Import sql file in node.js and execute against PostgreSQL

I'm looking for an efficient way to take a raw sql file and have it executed synchronously against a postgres database, akin to if you ran it through psql. I have an sql file which creates all ...
0
votes
1answer
1k views

PostgreSQL connection via javascript

I am searching for a way to connect to postgresql directly in the browser. Im trying to utilize nodejs and browserify but have had no luck so far with the bundling. Whenever I compile a script that ...
1
vote
1answer
2k views

error: there is no parameter $1

I get "error: there is no parameter $1" when I try to run this code using the node-postgres client: app.post('/newcause', function (req,res){ console.log(req.body); var g; var r = []; for (...
4
votes
1answer
1k views

Node-Postgres query method not calling its callback function

I have the following code which uses node-postgres: var client = new pg.Client(conString); client.connect(function(err) { if(err) { throw new Error(console.error('could ...
2
votes
0answers
290 views

pg doesn't seem to close the connection correctly

I am writing an application using Node.js and postgresql. When a user authenticates it hits the DB to check the user's password then supposedly closes the connection to the DB. However, if the user ...
3
votes
2answers
4k views

Return a value from an event emitter callback

I am using the postgresql module 'pg' in node. I would like to do some processing when a row is returned from the database, but I do not know how to return the value to the calling function. var ...