0
I have the following const
in my file Routes.js:
const database = [];
For learning purposes I’m using it as if it were my own "database", where according to the type of request I handle this variable... This variable is in the file mentioned above and I am using inside the routes after the use of certain middleware.
Using good practices I would like to know how I can use this variable among my middleware and my routes, what I tried to do was create a global middleware where I would do the following:
res.locals.database = [];
next();
But this code "erases" the variable when the answer is given with the res.
It is also possible to shorten the
database.js
formodule.exports = { /* ... */ }
, since the variable is only exported, it does not need it, just export the literal object directly, but the variable can be useful to make it clear that that object is the database– Costamilam
Thank you both, I enjoyed both replies.
– user148754