title: What is the correct way to retrieve data from database using nodejs and MySQL?
body: <p>I've written a code that should retrieve data from database with nodejs and mysql but it's not working.</p>
  
  <p>It says the I didn't installed the mysql module but I did, using npm install:
  <a href="https://i.stack.imgur.com/5xxlc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5xxlc.png" alt="enter image description here"></a></p>
  
  <p>The proof that I installed the mysql module successfully:
  <a href="https://i.stack.imgur.com/uxtL6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uxtL6.png" alt="enter image description here"></a></p>
  
  <p>Is my code ok ? Keep in mind that I'm completely new to node.js.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var http = require('http');
  
  http.createServer(function(request, response){
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.write('My first node server...');
    var mysql = require('mysql');
     var connection = mysql.createConnection({
      host :  'localhost:8888',
      user : 'root',
      password: '',
      database: 'test'
     });
  
     connection.connect();
  
     connection.query('SELECT * FROM tabel_test', function(err, rows, fields){
       if (!err) {
        console.log('The result is ', rows);
       } else {
        console.log('No results.');
       }
     });
  
    connection.end();
   response.end();
  }).listen(8888);</code></pre>
  </div>
  </div>
  </p>