node.js - Koa-pg Can't find module pg -
hey i'm trying nodejs koa talk postgres using koa-pg module, keep getting 'can't find module pg' error. i've tried follow koa-pg examples, have come short...so advice on how progress appreciated.
if created app.js file follows:
var koa = require('koa'); var route = require('koa-route'); var koapg = require('koa-pg'); var roads = require('./controllers/roads'); var app = module.exports = koa(); app.use(route.get('/roads/bbox/', roads.bbox)); app.listen(3000); console.log('listening on port 3000');
and created controller file follows:
var credentials = require('../credentials.js'); var environment = credentials.dev; app.use(koapg('postgres://' + environment.user + '@' + environment.host + ':' + environment.port + '/' + environment.database)) module.exports.bbox = function * bbox(next) { var result = yield this.koapg.db.client.querypromise('select now()') console.log('result: ', result) this.body = result.rows[0].now.toisostring() };
but i'm getting following error:
module.js:338 throw err; ^ error: cannot find module 'pg' @ function.module._resolvefilename (module.js:336:15) @ function.module._load (module.js:278:25) @ module.require (module.js:365:17) @ require (module.js:384:17) @ object.<anonymous> (c:\users\user\documents\restful_koa\node_modul es\koa-pg\index.js:12:27) @ module._compile (module.js:460:26) @ object.module._extensions..js (module.js:478:10) @ module.load (module.js:355:32) @ function.module._load (module.js:310:12) @ module.require (module.js:365:17)
this personal project i'd love understand i'm going wrong. cheers
as mentioned in comments:
you need install pg
module via npm install pg
or npm install pg --save
if want save package.json
.
the reason need koa-pg
has co-pg
dependency when install former latter installed. pg
not dependency of co-pg
, why have install separately.
Comments
Post a Comment