var express = require('express');
var ip = require("ip");
var app = express();

app.get('/', function (req, res) {
  var r = Math.floor(Math.random() * 5) + 1;
  res.send({res: calcFibonacci(30), ip: ip.address(), time: new Date()});
});

var server = app.listen(3000, function () {

  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

var calcFibonacci = function(n) {
  if (n < 2) return n;
  return calcFibonacci(n - 2) + calcFibonacci(n - 1);
};

var rFact = function(num){
    if (num === 0)
      { return 1; }
    else
      { return num * rFact( num - 1 ); }
};

var getPrimes = function(max) {
    var sieve = [], i, j, primes = 0;
    for (i = 2; i <= max; ++i) {
        if (!sieve[i]) {
            // i has not been marked -- it is prime
            primes = primes +1;
            for (j = i << 1; j <= max; j += i) {
                sieve[j] = true;
            }
        }
    }
    return primes;
};