1)安装pg模块:
进入到/usr/local/lib:发现有一个node_schedules目录,里面放的是你安装的模块
npm install -g node-gyp
export $PATH=$PATH:/usr/local/pgsql/bin/
npm install pg //-g 表示全局
2)连接数据库并访问
连接字符串=“tcp:// 用户名 : 密码 @localhost:5432/ 库名”;
1) 事件形式:
var pg = require('pg');
var MATH = require('math');
var constring = "tcp://postgres: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)");