0

I have a nodejs application where i want to make connection with elasticsearch and other database like mongodb and then create server but i don't want to use callback functions . is there any way to hold execution of nodejs code while function is establishing connections with ES cluster.

function loadConfFile(){

}
/* wait for above to complete */
function createESConnection(){

}
/* wait for above to complete */
function createMongoDBConnection(){

}

const express = require('express');
/* and so on  */

1 Answer 1

1

Wrap into promise with async:

async function createESConnection(){

}

Use await to... well, wait until it ends:

let esConn = await createESConnection()

But there's a caveat: everything using that async function must go async as well (read "go Promise-based")

P.S. Hope you're not restricted to some relic JS version not having that

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.