Answer the question
In order to leave comments, you need to log in
How to use the base in modules?
I have a module in which the database is connected, I need to use it in all Express routers.
I could create a new connection, but I would like to somehow pass the class of work with the base through the context.
Please help me with advice to solve this problem.
app.use("/method", require("./test"));
const { Router } = require("express");
const router = Router();
router.get("/register", async (req, res) => {
const user = await db.query("SELECT * FROM `users`");
res.status(200).json({ result: { user } });
});
module.exports = router;
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