<commit_before>"use strict";
// Importing modules used. 
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var path = require('path');
var redis = require('redis');
var client = redis.createClient();

//Configuring view engine as jade
app.set('view engine', 'jade');

//Importing files used
var conf  = require('./server/conf.js');
var utils = require('./server/utils.js');
var notepadLive = require('./server/notepadLive.js');

//Running server on localhost:PORT
server.listen(conf.PORT);
console.log('Server running on '+conf.PORT);


//Serving index.html on localhost:PORT/ url
app.get('/', function (req, res) 
{
  var path_to_index = path.join(__dirname + conf.PATH_TO_INDEX_TEMPLATE);  
  notepadLive.get_idCount(utils,conf,client,function(err,idCount)
  {
    if(err)
    {
      console.log('ERROR: '+err);
      res.send('ERROR');
      //error function
    }
    else
    {
      var options = {};
      options.idCount = idCount;
      options.PORT = conf.PORT;
      options.baseUrl = conf.baseUrl;
      options.submitId_actionUrl = conf.submitId_actionUrl;
      options.newId = Number(idCount)+1;
      res.render(path_to_index,options);
    }
  });
});


//Gets id as a get parameter, and returns the corresponding textarea
app.get(conf.submitId_actionUrl,function(req,res)
{
  if(!req.query.id)
  {
    res.send("Error.");
  }
  else
  {
    notepadLive.get_idCount(utils,conf,client,function(err,idCount)
    {
      if(err)
        console.log("Error: "+err);
      else
      {
        var path_to_project = path.join(__dirname+conf.PATH_TO_PROJECT_TEMPLATE)
        var id = Number(req.query.id);
        idCount = Number(idCount);
        if(id>idCount)
          notepadLive.set_idCount(utils,conf,client,id,function(err)
          {
            if(err) console.log("Error: "+err);
         });
        var options = {
          id : id,
          baseUrl : conf.baseUrl,
        };
        notepadLive.fetch_projectValue(utils,conf,client,id,function(err,value)
        {
          if(err)
            console.log("ERROR: "+err);
          else
          {
            options.value = value;
            res.render(path_to_project,options);
          }
        });
      }
    });
  }
});




//Creating a constant live connection 
io.on('connection', function (socket) 
{<commit_msg>bug solved- user can't manually enter id greated than idCount+1 in get request.<commit_after>"use strict";
// Importing modules used. 
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var path = require('path');
var redis = require('redis');
var client = redis.createClient();

//Configuring view engine as jade
app.set('view engine', 'jade');

//Importing files used
var conf  = require('./server/conf.js');
var utils = require('./server/utils.js');
var notepadLive = require('./server/notepadLive.js');

//Running server on localhost:PORT
server.listen(conf.PORT);
console.log('Server running on '+conf.PORT);


//Serving index.html on localhost:PORT/ url
app.get('/', function (req, res) 
{
  var path_to_index = path.join(__dirname + conf.PATH_TO_INDEX_TEMPLATE);  
  notepadLive.get_idCount(utils,conf,client,function(err,idCount)
  {
    if(err)
    {
      console.log('ERROR: '+err);
      res.send('ERROR');
      //error function
    }
    else
    {
      var options = {};
      options.idCount = idCount;
      options.PORT = conf.PORT;
      options.baseUrl = conf.baseUrl;
      options.submitId_actionUrl = conf.submitId_actionUrl;
      options.newId = Number(idCount)+1;
      res.render(path_to_index,options);
    }
  });
});


//Gets id as a get parameter, and returns the corresponding textarea
app.get(conf.submitId_actionUrl,function(req,res)
{
  if(!req.query.id)
  {
    res.send("Error.");
  }
  else
  {
    notepadLive.get_idCount(utils,conf,client,function(err,idCount)
    {
      if(err)
        console.log("Error: "+err);
      else
      {
        var path_to_project = path.join(__dirname+conf.PATH_TO_PROJECT_TEMPLATE)
        var id = Number(req.query.id);
        idCount = Number(idCount);
        if(id <= (idCount + 1))
        {
          if(id == (idCount+1))
          {
            notepadLive.set_idCount(utils,conf,client,id,function(err)
            {
              if(err) console.log("Error: "+err);
            });
            var options = {
              id : id,
              baseUrl : conf.baseUrl,
            };
            notepadLive.fetch_projectValue(utils,conf,client,id,function(err,value)
            {
              if(err)
                console.log("ERROR: "+err);
              else
              {
                options.value = value;
                res.render(path_to_project,options);
              }
            });
          }
        }
        else
        {
          res.send("You can't manually enter id.");
        }
      }
    });
  }
});




//Creating a constant live connection 
io.on('connection', function (socket) 
{
{'fraction_non_alphanumeric': 0.14336704342653184, 'fraction_numerical': 0.00099147332936744, 'mean_word_length': 2.4196610169491524, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4051311', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1601, 'n_words': 304}