Connection to Mysql DB (with sequelize) fail

imulyssus
TRIAL

a year ago

original: Error: connect ECONNREFUSED ::1:3306

at TCPConnectWrap.afterConnect as oncomplete {

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 3306,

fatal: true

}

}

Node.js v18.20.2

The above error kept showing. I used mysql_url var from the db creation on Railway platform itself and try to connect as below. Is there anything wrong? I am new here.

// config.js file
require('dotenv').config(); // Assuming config.js is in a subdirectory
module.exports = {
production: {
url: process.env.MYSQLURL, dialect: 'mysql', }, }; // models/index.js file let sequelize; if (config.useenvvariable) { sequelize = new Sequelize(process.env[config.useenv_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(dirname) .filter(file => { return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); }) .forEach(file => { const model = require(path.join(dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
//index.js file (main file)
require('dotenv').config({ path: "./config.env" });

app.use(cors({
origin: 'http://localhost:3000',
methods: ["POST", "GET", "DELETE"],
credentials: true,
}));
app.use(bodyParser.json({ limit: "10mb" }));
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true }));
app.use(cookieParser());
sequel.sequelize.sync().then(() => {
app.listen(process.env.PORT, () => {
console.log('Running at 3001');
});
});

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

0 Replies

Connection to Mysql DB (with sequelize) fail - Railway Help Station