I have an application that has connects to Redis, Mongo, and Elasticsearch but how can I make sure all the connections are connected before the app is served? I notice that Elasticsearch usually takes longer and when I test my app using Supertest that the database connects but the console.info('Successfully connected to db');
doesn't log to the console before the tests start to run.
server.ts
const client = redis.createClient({ host: process.env.REDIS })
client.on('connect', function () {
console.log('Redis client connected');
});
mongoose
.connect(dbURL)
.then(() => {
return console.info(`Successfully connected to ${db}`);
})
.catch(error => {
console.error('Error connecting to database: ', error);
return process.exit(1);
});
};
const app = express();
export default app;
main.ts
import server from './server'
server.listen(8000)
Aucun commentaire:
Enregistrer un commentaire