Get data from AJAX request in NodeJS and store in DB
<p>I have a problem with getting data from client side in NodeJS.</p>
<p>On the client side I've prepared JSON data as you can see in <a href="http://codepen.io/anon/pen/eJyear?editors=101" rel="nofollow noreferrer">codepen</a></p>
<p>On the server side I'm trying to get these data from the client:</p>
<pre><code>var express = require('express');
var mysql = require('mysql');

var app = express();

app.use('/', express.static('../client/app'));
app.use('/bower_components', express.static('../client/bower_components/'));

var server = require('http').createServer(app);

var bodyParser = require('body-parser');
app.jsonParser = bodyParser.json();
app.urlencodedParser = bodyParser.urlencoded({ extended: true });

//mysql connection setup
var connection = mysql.createConnection({
    host : &quot;localhost&quot;,
    port: &quot;3306&quot;,
    user : &quot;root&quot;,
    password : &quot;&quot;,
    database : &quot;db&quot;,
    multipleStatements: true
});

app.get(&quot;/cities&quot;, function(req, res) {

    console.log(res.body); //I'm getting nothing

    var data= {
        city: req.body.city,
        country: req.body.country
    };

    var query = connection.query('INSERT INTO table SET ?', data, function(err, res) {
        if (err) {
            console.log(err);
        } else {
            console.log('success');    
        }
    });
    console.log(res); 
});
    
server.listen(3000, function () {
    'use strict';
});
</code></pre>
<p>What I'm doing wrong? Is there a way to debug NodeJS in ST?
Thanks.</p>