<commit_before>'use strict';
const http = require('http');
const fs = require('fs');
const path = require('path');
const port = process.env.PORT || 8080;
const server = http.createServer();

server.on('request', onRequest);
server.on('listening', onListening);
server.listen(port);

function onRequest(req, res) {
   let fileName = path.join(__dirname, 'public', 'index.html');
   // join lets you concatenate routes and directories
   // __dirname is the current location where the application is running
   // instead of using it synchronously, we're going to make it asynchronously.
   // here is the first pattern of callback by default for node which is used in all the API's and libraries.
   // that pattern is: the 'error' as a first argument.
   fs.readFile(fileName, function(err, file) { // the last argument of an asynchronous function is a callback that's going to take a file after loaded.
      if(err) {
         res.end(err.message);
      }
      res.end(file);
   });
}

function onListening() {
   console.log('server listening on port ' + port);
}


<commit_msg>use of  'streams' to read files without overload the memory<commit_after>'use strict';
const http = require('http');
const fs = require('fs');
const path = require('path');
const port = process.env.PORT || 8080;
const server = http.createServer();

server.on('request', onRequest);
server.on('listening', onListening);
server.listen(port);

function onRequest(req, res) {
   let index = path.join(__dirname, 'public', 'index.html');
   // streams are mechanism to read files or sources of binary information that reads in a smarter way.
   // readFile loads the all file in memory, after the file is in memory, executes the callback and the file gets send in the response.
   // so how it works when working with streams?
   // while is reading the file it'll deliver as it goes having data available from the file and delivering it in the response.
   res.setHeader('Content-Type', 'text/html');
   let rs = fs.createReadStream(index);
   // so is reading the file and sending it
   rs.pipe(res);// here we're setting the
   rs.on('error', function(err) {
      rs.end(err.message);
   });
}

function onListening() {
   console.log('server listening on port ' + port);
}



{'fraction_non_alphanumeric': 0.11780336581045173, 'fraction_numerical': 0.00354295837023915, 'mean_word_length': 3.7961783439490446, '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': '4952722', 'n_tokens_mistral': 649, 'n_tokens_neox': 628, 'n_words': 258}