U
U
urgjfvuirakjkd2019-02-05 00:25:45
Node.js
urgjfvuirakjkd, 2019-02-05 00:25:45

With async and without - is there a difference?

I take the simplest example

var http = require('http');
http.createServer(function (req, res) {
//тут 60 секунд идет работа в СИНХРОННОМ режиме
//fs.readFileSync
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(req.url);
    res.end();
}).listen(8080);

How will the code differ if it is written like this?
var http = require('http');
http.createServer( async function (req, res) {
//тут 60 секунд идет работа в СИНХРОННОМ режиме
//fs.readFileSync
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(req.url);
    res.end();
}).listen(8080);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question