How do I set a variable thats outside the scope of a promise

How do I return a value from a promise (i probably didnt say that right)

eg. i need something like this

let is_connected;

test_connection(){
   let is_connected;
   promise().then(()=>is_connected = true).catch(()=> is_connected = false)
}

what I have now github:

const Sequelize = require('sequelize');

const db_config = {
    blog: {
        dialect: 'sqlite',
        storage: 'src/database/blog.sqlite'
    }
};

const blog_connection = new Sequelize(db_config.blog);

class DbController {
    constructor(db_connection) {
        this.db_connection = db_connection;
    }
    test_connection() {
        this.db_connection
            .authenticate()
            .then(() => {
                console.log('Successfully established connection');
            })
            .catch(() => {
                console.log('Failed to establish connection');
            });
    }
}

const Blog = new DbController(blog_connection);

Blog.test_connection();

Why do you need the is_connected variable? Why not just do what you want to inside the first then callback function if the connection is establish and do something else if it is not established. You can call a function inside the then callback.

1 Like

took your idea to make this

1 Like