我一直在尝试使用knex为Node设置postgres并且完全混淆了。
我已经使用postgres进行了knex设置,如下所示:
//db.js
const config = require('../knexfile.js');
const env = process.env.NODE_ENV || 'development';
const knex = require("knex")(config[env]);
module.exports = knex;
knex.migrate.latest([config]);
//knexfile.js
module.exports = {
development: {
client: 'pg',
connection: {
host: '127.0.0.1',
user: 'devUser',
password: 'dbpassword',
port: 5432,
database: 'example-name'
},
migrations: {
directory: __dirname + '/db/migrations'
},
seeds: {
directory: __dirname + '/db/seeds/development'
}
},
production: ....
}
然后当我尝试运行Node ...
const express = require('express');
const path = require('path');
const bodyParser = require("body-parser");
const app = express();
const routes = require('./routes.js');
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'client/build')));
app.use('/', routes);
app.set('port', (process.env.PORT || 3001));
app.listen(app.get('port'), () => {
console.log(`Find the server at: http://localhost:${app.get('port')}/`); // eslint-disable-line no-console
});
module.exports = app;
...我收到以下错误:
Unhandled rejection Error: connect ECONNREFUSED 127.0.0.1:5432
当您尝试在同一端口上运行两个进程时,我看到了此消息,但运行netstat -p tcp | grep 5432
则不返回任何内容。你能看到我错过了吗?