Sunday, 11 June 2017

How to use mysql-based node js (ft.json parsing)

  1. I want to use myslq based on node js to communicate with the current Android server. There is a problem in trying to parse json to send data to the server.

    app.get('/main', function(req, res) {
       if (req.cookies.auth) {
          fs.readFile('main.html', function(err, data) {
          connection.query('SELECT * from datework', function(err, rows) {
          if (err) throw err;
    
          console.log('rows: ', rows);
          console.log('json parsing...')
          res.json(rows);
    
          var st = rows[0].start_time;
          var et = rows[0].end_time;
          res.json(st+" , "+ et);
          console.log(st+" , "+ et);
          });
       });
    }});
    
    

The entire row of the query statement appears, but I want to specify only start_time and end_time.

  1. Finally, I want only start_time_ and end_time.

C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\Parser.js:79 throw err; // Rethrow non-MySQL errors ^

Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11) at ServerResponse.header (C:\Users\KTH_LAP\Desktop\G.D\node_modules\express\lib\response.js:725:10) at ServerResponse.json (C:\Users\KTH_LAP\Desktop\G.D\node_modules\express\lib\response.js:253:10) at Query._callback (C:\Users\KTH_LAP\Desktop\G.D\app.js:56:13) at Query.Sequence.end (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\sequences\Sequence.js:86:24) at Query._handleFinalResultPacket (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\sequences\Query.js:137:8) at Query.EofPacket (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\sequences\Query.js:121:8) at Protocol._parsePacket (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\Protocol.js:280:23) at Parser.write (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\Parser.js:75:12) at Protocol.write (C:\Users\KTH_LAP\Desktop\G.D\node_modules\mysql\lib\protocol\Protocol.js:39:16)



via Taehyeon

No comments:

Post a Comment