0

May I know why with below code. The browser takes a long time to load? I am new to express and node js. It takes almost 10s.If I was to replace res.write with console.log, the problem does not surface.

    app.get('/', function(req, res) {
    res.write("<!doctype html>");
    con.query('SELECT VoltageV from Voltage', function (err, rows, fields) {
        if (err) throw err
    var output = JSON.parse(JSON.stringify(rows));
            res.write("<SELECT>");
            res.write("</SELECT>");
    });
sunyata
  • 55
  • 7

1 Answers1

1

From Node.js api document Here it saids

If this method is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers.

This sends a chunk of the response body. This method may be called multiple times to provide successive parts of the body.

In short, your code is missing something that would affect performances, I think you will need to call res.writeHead() once and must be call before res.end()

But if this does not help at all, the answer from this link question here might answer your question about how res.write performance.

Awesome Cat
  • 50
  • 1
  • 9