Answer the question
In order to leave comments, you need to log in
How to arrange modules - routes in expressjs?
1) There is an index.js and db.js file with the database connection logic
const app = require('express')()
async function main() {
const db = await require('./db')
app.use('/api', require('./api')(db))
}
main()
const app = require('express')()
module.exports = function (db) {
const a = 1
const b = 2
function f() {}
function b() {}
app.get('/', () => {})
app.post('/', () => {})
return app
}
the 1st user accesses - ID is written in the middleware - the 2nd user accesses - the ID is recorded - the 1st user enters the route where this ID is required, will it be the 2nd user? Or everything is so single-threaded and fast that the 2nd user will not have time to overwrite the userId before the 1st gets into the route.
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