Skip to content

Error message when running code #153

Closed
@linnhege

Description

@linnhege

Hi!

I working on setting up my first node.js and postgres app and I keep getting this error message when I try to run my code:

D:\jobb\app>node web.js

D:\jobb\app\web.js:16
client.query('SELECT first_name FROM employees', function(err, result) {
    ^
    TypeError: Cannot call method 'query' of null
    at D:\jobb\app\web.js:16:12
    at adjustCallback (D:\jobb\app\node_modules\pg\node_modules\generi
    c-pool\lib\generic-pool.js:186:7)
    at exports.Pool.me.acquire (D:\jobb\app\node_modules\pg\node_modul
    es\generic-pool\lib\generic-pool.js:226:13)
    at pools.(anonymous function).genericPool.Pool.create.connectError (D:\jobb\
app\node_modules\pg\lib\index.js:30:11)
    at g (events.js:185:14)
    at EventEmitter.emit (events.js:88:17)
    at p.connect (D:\jobb\app\node_modules\pg\lib\client.js:106:12)
    at EventEmitter.emit (events.js:88:17)
    at Socket.p.connect (D:\jobb\app\node_modules\pg\lib\connection.js
    :47:12)
    at Socket.EventEmitter.emit (events.js:88:17)

Here is my web.js code:

var express = require('express')
    , routes = require('./routes')
    , app = express.createServer(express.logger())
    , pg = require('pg')
    , conString = "pg://user:pass@host:port/dbname"
    , port = process.env.PORT || 3000
    , client;


pg.connect(conString, function(err, client) {
    client.query('SELECT first_name FROM employees', function(err, result) {
        if(err) {
            console.log(err);
        }
        else {
            console.log("first name: ", result.rows[0].first_name);
        }
    });
});

Am I doing something wrong or is there a bug in your pg-code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions