title: Node.JS + mySQL -> How to do the ajax call and access the data on server.js?
body: <p>So this is my server.js file, where the db is being connected to :</p>
  
  <pre><code>var app = require('express')();
  var mysql = require('mysql');
  var db = mysql.createConnection({
  
      host: 'localhost',
      user: 'root',
      password: '',
      database: 'user_data',
      port: 3306
  });
  db.connect();
  
  app.get('/', function (req, res) {
      res.sendFile(__dirname + "/start.html");
  });
  
  app.listen(3000);
  </code></pre>
  
  <p>So I want to make something like a registration form, where you input your username and password. Then, after you click the submit button, the username and password are supposed to go straight to the mySQL database. So apparently, I need an ajax call which sends the data to that server, but I don't know how to access it on the server.js.</p>
  
  <pre><code>$("button#submit").click(function () {
        $.ajax({
             'url': 'http://localhost:3000',
             'type': 'post',
             'data': {
                  'username': $("#usr").val(),
                  'password': $("#pwd").val()
             },
             'success': function (data) {
                  alert('Data: ' + data);
             }
          });
    })
  </code></pre>
  
  <p>After I get that data on the server.js, I will obviously want to make a query (to insert the values) but how do I get the data?</p>