Here is a simple program:
var express = require('express');
var app = express.createServer();
var count = 0;
app.get("/", function(req, res) {
res.send(count.toString());
count++;
});
app.listen(3000);
When I open it in two different browsers, the first displays 0
and the second displays 1
.
Why? They are different sessions so I expect node.js use different child processes for them. My understanding, with PHP, is that sharing variables should be implemented using databases.
Why can node.js do this without any external storage? Is it a single-process but multiple threads?
How do I declare a variable that belongs to a specific session?