When I execute this program everything works fine:
const Sequelize = require("sequelize");
const Conn = new Sequelize("data","postgresql","postgresql", {
'host' : "localhost",
'dialect' : "postgres",
'port' : "1337"
})
// piece of code to be added here
Conn.sync().then(function(){
console.log('DB connection sucessful.');
}, function(err){
console.log(err);
});
the Console logs: DB connection successful.
When I add this line however:
const User = Conn.define('user', {
firstName: {
type: Sequelize.STRING
},
lastName: {
type: Sequelize.STRING
}
});
I get this error message:
{ SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:1337 at connection.connect.err (G:\projects\investcrypto\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:95:24) at Connection.connectingErrorHandler (G:\projects\investcrypto\node_modules\pg\lib\client.js:123:14) at emitOne (events.js:115:13) at Connection.emit (events.js:210:7) at Socket. (G:\projects\investcrypto\node_modules\pg\lib\connection.js:71:10) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) name: 'SequelizeConnectionRefusedError', parent: { Error: connect ECONNREFUSED 127.0.0.1:1337 at Object.exports._errnoException (util.js:1024:11) at exports._exceptionWithHostPort (util.js:1047:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14) code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 1337 }, original: { Error: connect ECONNREFUSED 127.0.0.1:1337 at Object.exports._errnoException (util.js:1024:11) at exports._exceptionWithHostPort (util.js:1047:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14) code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 1337 } }
Versions: npm: 5.3.0 node: 8.2.1 sequelize: 4.8.3 pg: 7.3.0 pg-hstore 2.3.2