<commit_before>var http = require('http');
// var url = require('url');
// require('dotenv').load()
//var db = require('monk')(process.env.MONGOLAB_URI);
var db = require('monk')('localhost/tasksdb');
var tasks = db.get('tasks');

var server = http.createServer(function (req, res) {
  if(req.method != 'GET'){
    return res.end('Send me a GET\n');
  }
  tasks.find({}, function(err, tasks) {
    res.writeHead(200, {'Content-Type':'application/json'});
    res.end(JSON.stringify(tasks)); // tasks is an array here.
  }); // without the POST boilerplate, this is 20 lines
  // if(req.method == "POST") {
  //   tasks.insert({
  //     //put new task description into db . . .
  //   });
  // }
});

server.listen(Number(process.argv[2]));<commit_msg>Set up server to serve index.html as wel<commit_after>var http = require('http');
var url = require('url');
var staticServer = require('node-static');
// require('dotenv').load()
//var db = require('monk')(process.env.MONGOLAB_URI);
var db = require('monk')('localhost/tasksdb');
var tasks = db.get('tasks');

var file = new(staticServer.Server)();

var server = http.createServer(function (req, res) {
  var urlKeys = url.parse(req.url, true);
  if(req.method != 'GET'){
    return res.end('Send me a GET\n');
  }
  if (urlKeys.pathname == '/api/tasks'){
    tasks.find({}, function(err, tasks) {
      res.writeHead(200, {'Content-Type':'application/json'});
      res.end(JSON.stringify(tasks)); // tasks is an array here.
    });
  }
  else {
    file.serve(req, res);
  }
  // if(req.method == "POST") {
  //   tasks.insert({
  //     //put new task description into db . . .
  //   });
  // }
});

server.listen(Number(process.argv[2]));
{'fraction_non_alphanumeric': 0.20943952802359883, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 3.3824289405684755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6105654', 'n_tokens_mistral': 589, 'n_tokens_neox': 577, 'n_words': 128}