1) install the pg module: Enter/usr/local/lib: A node_schedules directory is found, the module npm install-g node_gyp export $ PATH = $ PATH:/usr/local/pgsql/bin/npm install pg //-g indicates global 2) connect to the database and access the connection string = "tcp: // User name: password @ localhost: 5432/Database Name"; 1) event format: var pg = require ('pg '); var MATH = require ('Math'); var constring = "tcp: // s: 1234 @ localhost/my"; var client = new pg. client (constring); client. connect (); client. query ("create temp table beatle (name varchar (10), height integer)"); client. query ("insert into beatle (name, height) values ('john', 50)"); client. query ("insert into beatle (name, height) values ($1, $2)", ['brown ', 68]); var query = client. query ("select * from beatle"); query. on ('row', function (row) {console. log (row); console. log ("Beatle name: % s", row. name); console. log ("beatle height: % d' % d \" ", MATH. floor (row. height/12), row. height % 12) ;}); query. on ('end', function () {client. end () ;}); test successful. Output content: {name: 'john', height: 50} Beatle name: john beatle height: 4'2 "{name: 'Brown ', height: 68} Beatle name: brown beatle height: 5 '8 "2) callback function form: var pg = require ('pg '); var conString = "tcp: // postgres: 1234 @ localhost/my"; var client = new pg. client (conString); client. connect (function (err) {client. query ('select NOW () AS "theTime" ', function (err, result) {console. log (result. rows [0]. theTime); client. end () ;})}); the test is successful. The output result is Wed Jan 23 2013 14:30:12 GMT + 0800 (CST) 3). Use the callback method to implement the above event format: var pg = require ('pg '); var MATH = require ('Math'); var constring = "tcp: // s: 1234 @ localhost/my "; var client = new pg. client (constring); client. connect (function (err) {client. query ("create temp table beatle (name varchar (10), height integer)"); client. query ("insert into beatle (name, height) values ('john', 50)"); client. query ("insert into beatle (name, height) values ($1, $2)", ['brown ', 68]); client. query ("select * from beatle", function (err, result) {console. log (result); for (var I = 0; I <result. rowCount; I ++) {console. log (result. rows [I]); console. log ("Beatle name: % s", result. rows [0]. name); console. log ("beatle height: % d' % d \" ", MATH. floor (result. rows [0]. height/12), result. rows [0]. height % 12);} client. end () ;}); the test is successful. The output result is: {command: 'select', rowCount: 2, oid: NaN, rows: [{name: 'john', height: 50}, {name: 'brown ', height: 68}]} {name: 'john', height: 50} Beatle name: john beatle height: 4 '2 "{name: 'brown ', height: 68} Beatle name: john beatle height: 4'2"