node-postgres

node server can't connect to postgres db

ⅰ亾dé卋堺 提交于 2019-12-04 05:19:00
I recently switched from MySQL to postgres as my database for an node.js project. While I'm able to reach my remote postgres database from my local pgAdmin III (OSX) client, so far I've been unable to connect to my database through node.js. I'm sure that the credentials I entered for pgAdmin and my node.js were exactly the same. The other thing I've tried was setting my local ipadress to trust in stead of md5 in the pg_hba.conf at my database server. Is there anything I did wrong? My favourite search engine came up with some worrying hits about resetting my local os. I just used the example

How do I use node-postgres in a server?

落爺英雄遲暮 提交于 2019-12-04 01:39:52
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 noticed 'out of memory' errors on Heroku when trying to connect. My database has only 10 rows, so I don't see how this could be happening. All of my database access is of this form: client.query('SELECT * FROM table', function (err, result) { if (err) { res.send(500, 'database error'); return; } res.set('Content-Type', 'application/json'); res.send(JSON

node.js, pg, postgresql and insert queries (app hangs)

依然范特西╮ 提交于 2019-12-03 13:48:00
问题 I have the following simple node application for data insertion into postgres database: var pg = require('pg'); var dbUrl = 'tcp://user:psw@localhost:5432/test-db'; pg.connect(dbUrl, function(err, client, done) { for (var i = 0; i < 1000; i++) { client.query( 'INSERT into post1 (title, body, created_at) VALUES($1, $2, $3) RETURNING id', ['title', 'long... body...', new Date()], function(err, result) { if (err) { console.log(err); } else { console.log('row inserted with id: ' + result.rows[0]

query.on is not a function

两盒软妹~` 提交于 2019-12-03 10:37:38
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 function". I have searched extensively on how to resolve this but can't seem to find any documentation on the .on function. I know that the connection is successful because when I query the db from terminal, the two new rows have been added. jsontest.js var pg = require('pg'); var conString = "postgres://[username]:[password]@localhost:5432/VONKTA1"; //username and password masked var client = new pg

when to disconnect and when to end a pg client or pool

南笙酒味 提交于 2019-12-03 09:38:35
My stack is node, express and the pg module. I really try to understand by the documentation and some outdated tutorials. I dont know when and how to disconnect and to end a client. For some routes I decided to use a pool. This is my code const pool = new pg.Pool({ user: 'pooluser',host: 'localhost',database: 'mydb',password: 'pooluser',port: 5432}); pool.on('error', (err, client) => { console.log('error ', err); process.exit(-1); }); app.get('/', (req, res)=>{ pool.connect() .then(client => { return client.query('select ....') .then(resolved => { client.release(); console.log(resolved.rows);

Authentication error when connecting to Heroku PostgreSQL database

余生颓废 提交于 2019-12-03 06:42:14
问题 I'm developing a Node.js application using PostgreSQL and hosting on Heroku. My problem is that I get an authentication error like so: 14:32:05 web.1 | { [error: no pg_hba.conf entry for host "193.40.244.196", user "username", database "database_name", SSL off] 14:32:05 web.1 | length: 168, 14:32:05 web.1 | name: 'error', 14:32:05 web.1 | severity: 'FATAL', 14:32:05 web.1 | code: '28000', 14:32:05 web.1 | detail: undefined, 14:32:05 web.1 | hint: undefined, 14:32:05 web.1 | position:

node.js, pg, postgresql and insert queries (app hangs)

北慕城南 提交于 2019-12-03 04:49:51
I have the following simple node application for data insertion into postgres database: var pg = require('pg'); var dbUrl = 'tcp://user:psw@localhost:5432/test-db'; pg.connect(dbUrl, function(err, client, done) { for (var i = 0; i < 1000; i++) { client.query( 'INSERT into post1 (title, body, created_at) VALUES($1, $2, $3) RETURNING id', ['title', 'long... body...', new Date()], function(err, result) { if (err) { console.log(err); } else { console.log('row inserted with id: ' + result.rows[0].id); } }); } }); After I run node app.js in terminal it inserts 1000 rows into database, then

Authentication error when connecting to Heroku PostgreSQL database

我是研究僧i 提交于 2019-12-02 20:19:21
I'm developing a Node.js application using PostgreSQL and hosting on Heroku. My problem is that I get an authentication error like so: 14:32:05 web.1 | { [error: no pg_hba.conf entry for host "193.40.244.196", user "username", database "database_name", SSL off] 14:32:05 web.1 | length: 168, 14:32:05 web.1 | name: 'error', 14:32:05 web.1 | severity: 'FATAL', 14:32:05 web.1 | code: '28000', 14:32:05 web.1 | detail: undefined, 14:32:05 web.1 | hint: undefined, 14:32:05 web.1 | position: undefined, 14:32:05 web.1 | internalPosition: undefined, 14:32:05 web.1 | internalQuery: undefined, 14:32:05

Node calling postgres function with temp tables causing “memory leak”

人走茶凉 提交于 2019-12-01 08:03:41
I have a node.js program calling a Postgres (Amazon RDS micro instance) function, get_jobs within a transaction, 18 times a second using the node-postgres package by brianc. The node code is just an enhanced version of brianc's basic client pooling example , roughly like... var pg = require('pg'); var conString = "postgres://username:password@server/database"; function getJobs(cb) { pg.connect(conString, function(err, client, done) { if (err) return console.error('error fetching client from pool', err); client.query("BEGIN;"); client.query('select * from get_jobs()', [], function(err, result)

Node calling postgres function with temp tables causing “memory leak”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 05:38:46
问题 I have a node.js program calling a Postgres (Amazon RDS micro instance) function, get_jobs within a transaction, 18 times a second using the node-postgres package by brianc. The node code is just an enhanced version of brianc's basic client pooling example, roughly like... var pg = require('pg'); var conString = "postgres://username:password@server/database"; function getJobs(cb) { pg.connect(conString, function(err, client, done) { if (err) return console.error('error fetching client from