这是我的config.json文件:
{
"development": {
"username": "xyz",
"password": "password123",
"database": "db1",
"host": "localhost",
"dialect": "postgres"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
这是我的app.js文件
const useit = async () => {
await sequelize.authenticate();
}
//Listening
app.listen({ port: 8000 }, async () => {
console.log('Server up on http://localhost:8000')
useit();
console.log('Database Connected!')
await sequelize.sync({alter:true});
})
module.exports = app;
在ORM中,我使用Sequalize沿着postgres作为我的后端。一切都很好,我所有的REST API端点都很好,但是,当我运行npm run test时,我收到了以下错误:
console.warn
failed to find WebSocket
at $.send (eval at oo_cm (app.js:386:57), <anonymous>:1:5120)
console.warn
failed to find WebSocket
at $.send (eval at oo_cm (app.js:386:57), <anonymous>:1:5120)
FAIL test/app.test.js
✕ GET random not found endpoint (33 ms)
● GET random not found endpoint
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
at Client._connectionCallback (node_modules/sequelize/src/dialects/postgres/connection-manager.js:179:24)
at Client._handleErrorWhileConnecting (node_modules/pg/lib/client.js:316:19)
at Client._handleErrorEvent (node_modules/pg/lib/client.js:326:19)
at Socket.reportStreamError (node_modules/pg/lib/connection.js:57:12)
● GET random not found endpoint
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
at Client._connectionCallback (node_modules/sequelize/src/dialects/postgres/connection-manager.js:179:24)
at Client._handleErrorWhileConnecting (node_modules/pg/lib/client.js:316:19)
at Client._handleErrorEvent (node_modules/pg/lib/client.js:326:19)
at Socket.reportStreamError (node_modules/pg/lib/connection.js:57:12)
我不知道整个代码的问题是什么。试图改变配置文件和app.js里面的东西,但没有工作。我的测试用例总是失败与相同的错误。请帮助我。
1条答案
按热度按时间mccptt671#
3306是MySQL的端口号。但是,您似乎是使用PostgreSQL驱动程序连接的。