title: Mysql make nodejs server crash
body: <p>So when I'm trying to connect to my database my nodescript crash...</p>
  <p>This is my code :</p>
  <pre><code>    app.get('/login', (req, res) =&gt; {
      res.setHeader('Content-Type', 'application/json');
      const queryObject = JSON.stringify(url.parse(req.url,true).query);
      var queryParsed = JSON.parse(queryObject);
      $ip = req.ip;
      $ip = $ip.replace('::ffff:', '')
  
      var con = mysql.createConnection({
          host: &quot;localhost&quot;,
          user: &quot;root&quot;,
          password: &quot;***&quot;,
          database: &quot;project&quot;
      });
        
      con.connect(function(err) {
          var req_search_user = &quot;SELECT * FROM users WHERE username = ? AND password = ?&quot;;
          con.query(req_search_user, [queryParsed.username, queryParsed.password], function (err, result) {
              var resultJson = JSON.stringify(result);
              var resultParsed = JSON.parse(resultJson);
  
              if(resultParsed.length != 0){
  
                  con.connect(function(err) {
                      con.query(&quot;UPDATE users SET ip = ? WHERE id = ?&quot;, [$ip, resultParsed[0].id], function (err, result, fields) {});
                  });
  
                  if(resultParsed[0].date_time_activate == null){
                      con.connect(function(err) {
                          con.query(&quot;UPDATE users SET date_time_activate = NOW() WHERE id = ?&quot;, [resultParsed[0].id], function (err, result, fields) {});
                      });
                  }
  
                  res.end(JSON.stringify({ &quot;Login&quot;: &quot;1&quot; }));
              }else{
                  res.end(JSON.stringify({ &quot;Login&quot;: &quot;0&quot; }));
              }
          });          
      });
  });
  </code></pre>
  <p>And when the server crash it return this in the console :</p>
  <pre><code>SyntaxError: Unexpected token u in JSON at position 0
      at JSON.parse (&lt;anonymous&gt;)
      at Query.&lt;anonymous&gt; (/var/api/app.js:57:37)
      at Query.&lt;anonymous&gt; (/var/api/node_modules/mysql/lib/Connection.js:526:10)
      at Query._callback (/var/api/node_modules/mysql/lib/Connection.js:488:16)
      at Query.Sequence.end (/var/api/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
      at /var/api/node_modules/mysql/lib/protocol/Protocol.js:236:14
      at processTicksAndRejections (internal/process/task_queues.js:75:11)
  </code></pre>
  <p>So when I'm running it in local it's working but not on the server... So I guess it's a mysql problem... Any idea ? Thank you :)</p>
  <ul>
  <li>I'm running on Ubuntu 20.04</li>
  </ul>