U
U
urajo2019-09-12 21:25:08
JavaScript
urajo, 2019-09-12 21:25:08

How to refer to an element of an object in nodejs?

After querying the database, I get an object [ RowDataPacket { id: 1, login: 'Uri', password: '9696GORYACHEV' } ]
how to display just id?
Tried i[id]/i['id'] - doesn't display
Trying

for(var kay in i) {
        var w = i[kay];
        response.send(w);
    }

Displays the entire object
. At the same time, the server constantly closes the connection and crashes.
events.js:180 thrower
; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (W:\domains\mysql1\node_modules\mysql\lib\protocol\Protocol.js:112:13)
at Socket. (W:\domains\mysql1\node_modules\mysql\lib\Connection.js:97:28)
at Socket. (W:\domains\mysql1\node_modules\mysql\lib\Connection.js:525:10)
at Socket.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1161:12)
at processTicksAndRejections (internal /process/task_queues.js:77:11)
Emitted 'error' event at:
at Connection._handleProtocolError (W:\domains\mysql1\node_modules\mysql\lib\Connection.js:426:8)
at Protocol.emit (events.js:203:13)
at Protocol._delegateError (W:\domains\mysql1\node_modules\mysql\lib\protocol\Protocol.js:398:10)
at Protocol.end (W:\domains \mysql1\node_modules\mysql\lib\protocol\Protocol.js:116:8)
at Socket. (W:\domains\mysql1\node_modules\mysql\lib\Connection.js:97:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}

How to be in the first case and how in the second?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail, 2019-09-12
@makarychev13

response.send() can be called once, and you are trying to pull it in a loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question