N
Neon15mo ago
genetic-orange

SequelizeConnectionRefusedError

Hello, I'm trying to use Neon with Sequelize and keep running into a [SequelizeConnectionRefusedError]. Migration and seeding with Sequelize's CLI both work, but when I try to access the database while the main application is running—e.g. by calling the model's findOne, findAll, create, or bulkCreate method—I hit the error, even though findOne and bulkCreate work during seeding. My Sequelize config.js:
require('dotenv').config();

module.exports = {
development: {
...
},
testing: {
url: process.env.DB_FILE,
dialect: 'postgres',
dialectOptions: { ssl: { require: true } },
},
};
require('dotenv').config();

module.exports = {
development: {
...
},
testing: {
url: process.env.DB_FILE,
dialect: 'postgres',
dialectOptions: { ssl: { require: true } },
},
};
And my .env:
DB_FILE='<connection string copied from project dashboard>&connect_timeout=10'
NODE_ENV=testing
DB_FILE='<connection string copied from project dashboard>&connect_timeout=10'
NODE_ENV=testing
I tried adding &connect_timeout=10 to my URL, but nothing changed, so I'm guessing it isn't a timeout error. Unfortunately, I can only see the Sequelize error, not the Neon response that triggers it, which has made troubleshooting difficult. Any help would be appreciated. (Full error below.)
5 Replies
genetic-orange
genetic-orangeOP15mo ago
ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED ::1:5432
at Client._connectionCallback (C:\Users\johal\projects\momo\src\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:133:24)
at Client._handleErrorWhileConnecting (C:\Users\johal\projects\momo\src\node_modules\pg\lib\client.js:327:19)
at Client._handleErrorEvent (C:\Users\johal\projects\momo\src\node_modules\pg\lib\client.js:337:19)
at Connection.emit (node:events:517:28)
at Socket.reportStreamError (C:\Users\johal\projects\momo\src\node_modules\pg\lib\connection.js:58:12)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
parent: Error: connect ECONNREFUSED ::1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
},
original: Error: connect ECONNREFUSED ::1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
}
}
ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED ::1:5432
at Client._connectionCallback (C:\Users\johal\projects\momo\src\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:133:24)
at Client._handleErrorWhileConnecting (C:\Users\johal\projects\momo\src\node_modules\pg\lib\client.js:327:19)
at Client._handleErrorEvent (C:\Users\johal\projects\momo\src\node_modules\pg\lib\client.js:337:19)
at Connection.emit (node:events:517:28)
at Socket.reportStreamError (C:\Users\johal\projects\momo\src\node_modules\pg\lib\connection.js:58:12)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
parent: Error: connect ECONNREFUSED ::1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
},
original: Error: connect ECONNREFUSED ::1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5432
}
}
fair-rose
fair-rose15mo ago
@Joy hi friend, it looks like you have the postgres address set to localhost. I would check your environment variables, my guess is how ever you set them for seeding clearly works, how ever you set them for your regular application is either not set or not set correctly. ::1 is ipv6 for the localhost or loopback address
genetic-orange
genetic-orangeOP15mo ago
Huh! thanks, I'll try to figure out how that happened solution: My Sequelize config needed a host property, and I needed PGHOST, PGDATABASE, PGUSER, and PGPASSWORD variables. Everything's working now. (thanks again for the help! it got me looking in the right places)
flat-fuchsia
flat-fuchsia15mo ago
GitHub
examples/with-sequelize/index.js at main · neondatabase/examples
Examples and code snippets demonstrating common ways of integrating Neon with various frameworks and languages. - neondatabase/examples
flat-fuchsia
flat-fuchsia15mo ago
you may use something like the following instead of destructing the environment variables

Did you find this page helpful?