D
D
DTX2020-05-09 21:12:05
Node.js
DTX, 2020-05-09 21:12:05

Is Expressjs Single Threaded?

Let's say I have an expressjs server. There is an apishka that returns something:

router.get('/test', async (req: Request, res: Response) => {
   return res.json(await ConstantsDao.get())
})

Can I add a "global" variable A here and be sure that it will be the same for all clients? Those. will it be the same variable for all clients or not?

let A; - вот тут
router.get('/test', async (req: Request, res: Response) => {
   return res.json(await ConstantsDao.get())
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2020-05-09
@DirecTwiX

It will be the same, yes, but I do not recommend doing this if you decide to use this variable as a fast in-memory cache. Because in this case, your API becomes not scalable, because. the value of variable A may then be different for different nodes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question