progs/App2.js
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 11 Oct 2016 15:14:59 +0100
changeset 477 b2c5a721f360
parent 172 aa7ddfee35c9
permissions -rw-r--r--
updated

var express = require('express');
var cookie  = require('cookie-parser')
var crypto = require('crypto');

var app = express();
app.use(cookie());

app.get('/', function(req, res){
    var counter = parseInt(req.cookies.counter) || 0;
    res.cookie('counter', counter + 1);
    if (counter >= 5) {
	res.write('You are a valued customer ' + 
		  'visting the site ' + counter + ' times.');
    } else {
	res.write('This is visit number '+ counter +'!');
    }
    res.end();
});

// starting the server
app.listen(8000);
console.log("Server running at http://127.0.0.1:8000/");