Answer the question
In order to leave comments, you need to log in
How to correctly implement the launch of Koa with the preliminary initialization of the application?
Before launching the Koa application (which should not be so important), I want to initialize the environment in which the application will work. For example, create a default user, set up a database, check the necessary directories, and so on. For example like this:
(async () => {
await Promise.all([createDefaultUser()]); // тут всякое инициализирующее
})()
.then(() => {
logger.info(`Start serve on ${config.appHost}:${config.appPort}`);
const server = app.listen(config.appPort, config.appHost);
})
.catch(err => {
logger.error(`App initialization error: ${err}`);
});
module.exports = server; // надо для нужд тестирования
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question