0
我想連接到我的數據庫,但我遇到了一些錯誤。對於這一切我都很新穎,如果我不清楚,我很抱歉。我能夠使用pgAdmin來運行查詢到我的數據庫,但我似乎無法得到它在這裏工作。基本Postgres和MassiveJS連接終止
這是我的錯誤:
/Users/patrickholley/Desktop/Dockbox/Dev-Mtn/w6/d3/massive-demo/node_modules/deasync/index.js:46
throw err;
^
Error: Connection terminated
at Connection.<anonymous> (/Users/patrickholley/Desktop/Dockbox/Dev-Mtn/w6/d3/massive-demo/node_modules/pg/lib/client.js:183:17)
at Object.onceWrapper (events.js:290:19)
at emitNone (events.js:86:13)
at Connection.emit (events.js:185:7)
at Socket.<anonymous> (/Users/patrickholley/Desktop/Dockbox/Dev-Mtn/w6/d3/massive-demo/node_modules/pg/lib/connection.js:66:10)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:501:12)
at Function.module.exports.loopWhile (/Users/patrickholley/Desktop/Dockbox/Dev-Mtn/w6/d3/massive-demo/node_modules/deasync/index.js:72:22)
at Object.connectSync (/Users/patrickholley/Desktop/Dockbox/Dev-Mtn/w6/d3/massive-demo/node_modules/deasync/index.js:44:19)
這裏是我的server.js:
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var massive = require('massive');
var app = express();
app.use(bodyParser.json());
var port = 3000;
var conn = massive.connectSync({
connectionString : "postgres://[email protected]/massive_demo"
});
app.set('db', conn);
var db = app.get('db');
app.get('/incidents', function(req, res) {
console.log('POST sighting');
});
app.post('/incidents', function(req, res) {
console.log('POST sighting');
});
app.listen(port, function() {
console.log("Started server on port", port);
});
真的不知道該說些什麼;我會盡我所能在任何地方澄清它不清楚的地方。
您的連接字符串未指定Postgres正在偵聽的端口,因此Massive會採用默認設置。如果你想使用非標準端口,你必須包含它:'postgres:// postgres @ localhost:5433/massive_demo'。 – dmfay
真棒,感謝您的額外洞察! –