<commit_before>var   
      mysql = require('mysql')
    , express = require('express')
    , url   = require('url')
    , http  = require('http')
    , sq    = require('squel')
;

/* DATABASE */

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '<PASSWORD>',
  database : 'weather'
});

connection.connect();


/* SERVER */

var app=express();

var port=1992, host='127.0.0.1';

app.get('/save', function (req, res) {
    
    var queryData=url.parse(req.url, true).query;
    // console.log(req.connection.remoteAddress, '=', queryData);

    // TODO [ok]
    //  check if query actually contains the parameters
    //  [] test:
    if (!queryData['id'] || !queryData['temp'] || !queryData['wind'] || !queryData['humid']) {
        console.err('Bad /save?.. request');
        return;
    };

    connection.query(
        sq.insert().into("data")
            .set("devID", parseInt(queryData['id']))
            .set("temp", parseFloat(queryData['temp']))
            .set("wind", parseFloat(queryData['wind']))
            .set("humid", parseFloat(queryData['humid']))
                .toString(), function (err, rows, fields) {
        if (!err) {
            // console.log('sol =', rows);
            console.log(queryData);
        } else {
            console.log(err);
        };
    });

    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write('continue');
    res.end('\n');

});

app.get('/read', function (req, res) {
    
    // res.writeHead(200, {'Content-Type': 'application/json'});
    res.json({'a':'b'});
    // res.end('\n');

})

app.listen(port);

// connection.end();   // [] TODO is commenting this bad?

console.log('Server running at http://'+host+':'+port+'/');<commit_msg>Respond with JSONs<commit_after>var   
      mysql = require('mysql')
    , express = require('express')
    , url   = require('url')
    , http  = require('http')
    , sq    = require('squel')
;

/* DATABASE */

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '<PASSWORD>',
  database : 'weather'
});

connection.connect();


/* SERVER */

var app=express();

var port=1992, host='127.0.0.1';

app.get('/save', function (req, res) {
    
    var queryData=url.parse(req.url, true).query;
    // console.log(req.connection.remoteAddress, '=', queryData);

    // TODO [ok]
    //  check if query actually contains the parameters
    //  [] test:
    if (!queryData['id'] || !queryData['temp'] || !queryData['wind'] || !queryData['humid']) {
        console.err('Bad /save?.. request');
        return;
    };

    connection.query(
        sq.insert().into("data")
            .set("devID", parseInt(queryData['id']))
            .set("temp", parseFloat(queryData['temp']))
            .set("wind", parseFloat(queryData['wind']))
            .set("humid", parseFloat(queryData['humid']))
                .toString(), function (err, rows, fields) {
        if (!err) {
            // console.log('sol =', rows);
            console.log(queryData);
        } else {
            console.log(err);
        };
    });

    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write('continue');
    res.end('\n');

});

app.get('/read/*', function (req, res) {
    
    // res.writeHead(200, {'Content-Type': 'application/json'});
    res.json({
        "area": ["kandy", "kagalla", "katugasthota"]
    });
    // res.end('\n');

})

app.listen(port);

// connection.end();   // [] TODO is commenting this bad?

console.log('Server running at http://'+host+':'+port+'/');
{'fraction_non_alphanumeric': 0.21067259588660367, 'fraction_numerical': 0.008893829905503057, 'mean_word_length': 2.4705882352941178, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5113142', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1154, 'n_words': 215}