node.js install postgreSQL 初体验
node.js install postgreSQL 初体验1:安装postgresql
2:命令行:
npm install pg
.......
【第一个难题】
我们需要安装python
http://dl.iteye.com/upload/attachment/0076/4133/965d030c-2c2b-3504-871b-485daf64de7c.jpg
【第二个难题】
这个错误的原因很令人头痛,查阅了很多资料无果。
尝试着在环境变量path里添加 C:\Program Files\PostgreSQL\9.2\bin 后继续无果
在自定义path继续中 添加C:\Program Files\PostgreSQL\9.2\bin
后OK
----------------------------------------------------------------------
3:测试代码
var express = require('express');var pg = require('pg');var app = express();////////////////////////////用户名:密码/服务器名/数据库名var conString = "postgres://postgres:password@localhost/test";var client = new pg.Client(conString);client.connect();client.query('INSERT INTO t_user(id, name) VALUES($1, $2)', );app.get('/', function(req, res){query = client.query('SELECT COUNT(id) AS n FROM t_user');query.on('row', function(result) { console.log(result); if (!result) { return res.send('No data found'); } else { res.send('Visits today: ' + result.n); }});});app.listen(3000);console.log('Listening on port 3000');
测试OK
页:
[1]