Unable to connect to database using sequelize

I have not been able to connect to my database using Sequelize because it gives me the following error: Unable to connect to the database: HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND

PD: I am new to Fly.io

Connection code

const { Sequelize } = require("sequelize");

const databaseUrl = process.env.DATABASE_URL;

// Check if the environment variable is set
if (!databaseUrl) {
  console.error("The environment variable is not defined.");
  process.exit(1); // Terminates the process with an error code
}

// Configure Sequelize with direct URL
exports.sequelize = new Sequelize(databaseUrl, {
  dialect: "postgres",
  dialectOptions: {
    ssl: {
      require: true,
      rejectUnauthorized: false,
    },
  },
});

Any kind of help will help me, thank you.

For starters, you do not want ssl, so delete dialectOptions.

I haven’t tried Sequelize myself, but based on App Connection Examples · Fly Docs, I would suggest adding:

host: new URL(databaseUrl).hostname

Thanks, it worked for me.