1

This is the code I'm using to start Sequelize and authenticate. I need to await the authenticate() method to make sure database is ready to be used by other app components:

'use strict';

(async () =>
{
    let Sequelize=require('sequelize');
    let seq = new Sequelize('admin_apptoolset', 'root', 'root', 
        {
            host: 'localhost',
            dialect: 'mysql',
            operatorsAliases: false,
            pool: 
            {
                max: 5,
                min: 0,
                acquire: 30000,
                idle: 10000
            }
        });

        console.log("Trying to connect to database...");
        await seq.authenticate();
        console.log("Connected to database...");

        return;
})()

I can see how both console logs are dumped to the console but the process doesn't exit after the return. Shouldn't it work?

Thanks in advance.

0

1 Answer 1

1

You need to disconnect from database, because it's prevent event loot from exit. Add seq.close(); before return;

(async () => {
    let Sequelize = require("sequelize");
    let seq = new Sequelize("admin_apptoolset", "root", "root", {
        host: "localhost",
        dialect: "mysql",
        operatorsAliases: false,
        pool: {
            max: 5,
            min: 0,
            acquire: 30000,
            idle: 10000
        }
    });
    console.log("Trying to connect to database...");
    await seq.authenticate();
    console.log("Connected to database...");
    seq.close(); // close connection
    return;
})();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.