Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 447 Bytes

async-local-storage.md

File metadata and controls

19 lines (15 loc) · 447 Bytes
title
Using `AsyncLocalStorage`

By default, domain api use used in the RequestContext helper. Since v4.0.3, you can use the new AsyncLocalStorage too, if you are on up to date node version:

const storage = new AsyncLocalStorage<EntityManager>();

const orm = await MikroORM.init({
  context: () => storage.getStore(),
  // ...
});

app.use((req, res, next) => {
  storage.run(orm.em.fork(true, true), next);
});