progs/ap2.js
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 02 Dec 2015 01:57:07 +0000
changeset 440 66f1d7e4f70b
parent 174 e2180cead443
child 531 35ffb7a7eafa
permissions -rw-r--r--
updated

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

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();
});

app.listen(8000);