JavaScript is run client side, so each user would be running the JS locally.
Edit: Jason pointed out in the comments that I missed the Node.js tag you put on the article; thus the above statement is not true for Node.js.
I understand your question to be "How can I have a 2 minute idle check written in JS?". Personally, I'd have a global in your JS code which keeps track of the last time the user performed an action. At the end of each JS function have this variable set with the current Time (More Info Here.). Next, use a JS interval to check that value periodically (More Info Here.).
You would end up with something like this:
var myTime = new Date().getTime();
var timeout = 2 * 60 * 1000;
var interval = 30 * 1000;
window.setInterval(checkTimeout(),interval);
function checkTimeout() {
var t = new Date().getTime();
t = t-myTime;
if (t >= timeout) {
alert("You've been Idle for 5s+");
}
window.setInterval(checkTimeout(),interval);
}
function setTime() {
myTime = new Date().getTime();
}
Here is an example on jsfiddle.