Node + Express: Does Express clone req and res objects for each request handler?

If Javascript copies objects by reference, does Express do the cloning of the objects reqand resbefore passing them to each request handler? If not, how does Express handle possible conflicts between routes running at the same time and using the same link to reqand res?

+4
source share
2 answers

Express does not clone reqand res. You can see that in this example the application:

var http = require('http');
var express = require('express');

var app = express();
var testReq, testRes;

app.use(function(req, res, next) {
  console.log('middleware');
  testReq = req;
  testRes = res;
  next();
});

app.get("*", function(req,res) {
  console.log('route')
  console.log('req the same? ' + (req === testReq)); // logs true
  console.log('res the same? ' + (res === testRes)); // logs true

  res.send(200);
});


http.createServer(app).listen(8080);

Test with curl:

$ curl localhost:8080

- , req res . , req.user.

Concurrency , Node.js - .

- get("*"), , .

+6

JavaScript , , . req res , .

+2

Source: https://habr.com/ru/post/1611320/


All Articles