Pg-promise: Invalid Property in initialization options

Created on 13 Jan 2017  路  4Comments  路  Source: vitaly-t/pg-promise

I am getting this just copying the example code and running that..

[ec2-user@ip-172-31-54-143 jobomatic_package]$ node index.js
WARNING: Invalid property 'host' in initialization options.
at Object. (/home/ec2-user/tmp/package/index.js:18:10)

------index.js-------

var  promise = require('bluebird');
var pgp = require('pg-promise');
var cn = {
    host: 'some.awsrds.us-east-1.rds.amazonaws.com', // 'localhost' is the default
    port: 5432, // 5432 is the default;
    database: 'database_dev1',
    user: 'database_user1',
    password: 'secretpassword'
};
var db = pgp(cn);
console.log("Start Query");
db.any("select * from public.account order by id asc")
   .then(function (data) {
         console.log("Data: " + data);
    })
   .catch(function (error) {
       console.log("Error: " + error);
   })
  .finally( function() {
       pgp.end();
  });

----end of file-----
this is the error i get

WARNING: Invalid property 'host' in initialization options.
at Object. (/home/ec2-user/tmp/package/index.js:18:10)

Start Query
/home/ec2-user/tmp/package/index.js:23
db.any("select * from public.account order by id asc")
^

TypeError: db.any is not a function
at Object. (/home/ec2-user/tmp/package/index.js:23:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:134:18)
at node.js:962:3

Most helpful comment

As per the Official Documentation:

step1:

var pgp = require('pg-promise')({
    // Initialization Options
});

step2:

var db = pgp(connection);

Check your code, it's not what you are doing :wink:

All 4 comments

As per the Official Documentation:

step1:

var pgp = require('pg-promise')({
    // Initialization Options
});

step2:

var db = pgp(connection);

Check your code, it's not what you are doing :wink:

_For those like me who have trouble finding the difference_: Double parenthesis are necessary while requiring pg-promise because it exports a function. The first parenthesis accepts the module name while the second is for the exported function's parameters.

var pgp = require('pg-promise')( /*in this case we pass no options );

@dyllandry It is the first thing that's explained: http://vitaly-t.github.io/pg-promise/

I see that now. I just got to the point of following documentation instead of solely tutorials, so I'm still trying to tell what's important and what's not. I'll add 'getting started' sections to the important list. I'll delete the comments if you like.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hawkeye64 picture hawkeye64  路  4Comments

dzaman picture dzaman  路  3Comments

Juanflugel picture Juanflugel  路  3Comments

cortopy picture cortopy  路  5Comments

realcarbonneau picture realcarbonneau  路  4Comments