question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: getaddrinfo ENOTFOUND undefined undefined:5432

See original GitHub issue
var express       = require('express');
var pg            = require('pg');
var CONSTANT      = require('../src/constant.js');
var router = express.Router();
var connectionString = CONSTANT.DB_NAME+'://'+CONSTANT.DB_USERNAME+':'+CONSTANT.DB_PASSWORD+'@'+CONSTANT.DB_URL+':'+CONSTANT.DB_PORT+'/'+CONSTANT.DB_SCHEMA;
var client = new pg.Client(connectionString);
client.connect();

var config = {
  user: CONSTANT.DB_USERNAME,
  database: CONSTANT.DB_SCHEMA,
  host: CONSTANT.DB_HOST,
  password: process.env.PGPASSWORD,
  port: CONSTANT.DB_PORT
};

console.log("config : "+JSON.stringify(config));
var pool = new pg.Pool(config);

pool.on('error', function(error, client) {
  if(err) {
    console.log(err);
  }
})

router.get('/testing', function(req, res, next) {
  console.log("--------------");
})

module.exports = router;

Below is the error am getting

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND undefined undefined:5432
    at errnoException (dns.js:27:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)

Also this link https://github.com/brianc/node-postgres doesn’t seem to be passing the host/hostname to the config param NodeJS version is 4.4.2… PostgreSQL version is 9.5.2

Looking at the error message undefined:5432 it looks like it is not finding the DB host name.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
arjungowdaacommented, Jul 22, 2016

Hi @brianc… I deleted my node_modules and did npm install again. After that am not getting that error. Assuming its resolved?

Just wanted to confirm with you before I close this thread.

3reactions
brianccommented, Jul 20, 2016

try this

var express       = require('express');
var pg            = require('pg');
var CONSTANT      = require('../src/constant.js');
var router = express.Router();
var config = {
  user: CONSTANT.DB_USERNAME,
  database: CONSTANT.DB_SCHEMA,
  host: CONSTANT.DB_HOST,
  password: process.env.PGPASSWORD,
  port: CONSTANT.DB_PORT
};

console.log("config : "+JSON.stringify(config));
var pool = new pg.Pool(config);
pool.query('SELECT NOW()', function(err, res) {
  if (err) throw err
  console.log(res.rows)
})

router.get('/testing', function(req, res, next) {
  console.log("--------------");
})

module.exports = router;

That should work if you’re using pg>=6.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS Postgres error getaddrinfo ENOTFOUND
The database name is people and it's running on port 8080 but in this error it's showing 5432 even if I declare the...
Read more >
Your server encountered an error (getaddrinfo ENOTFOUND ...
I'm expecting to be able to visual my data. Actual behavior. I setup forest admin with docker (the website gave me the command...
Read more >
ConnectionError: getaddrinfo ENOTFOUND postgres - Support
What is the problem? Be very detailed. I'm trying to use a local database and Nginx . I'm removing these services in my...
Read more >
Newbie - Trouble connecting to a hosted PostgreSQL database
I'm using ElephantSQL as my host (which uses Amazon's EC2) for my online database. When I make a call in my API, Node...
Read more >
Error: getaddrinfo ENOTFOUND postgres docker
If you try to run your JSON server and see this error message “getaddrinfo ENOTFOUND localhost,” it's happening because Webpack cannot find your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found