Take the tour ×

hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have tried it and it works but how can I remove/delete data from server using interval time like in javascript without have to restart node.js/ terminal prompt?.... example:

function del(){
if(time<timenow-1000){delete time;}}


I want to delete data less than two hours ago every one hours using interval time...thanks

share|improve this question
setInterval is the correct way to run code at intervals, but you're already using it. So what's the question? –  Joe White Jan 29 '12 at 6:55
my questi I can't delete it.how to delete data on server?if you try chat app chat.nodejs.org if you send data,data will push in server..ok I will explain details from beginning..first I will run node.js using command prompt(win)..I call it using node server.js command..then I open my browser http:\\localhost:8001 it will open html form for chating..I submit form and data will pushed into server,I close mybrowser and I open new another browser and data still exist..although I close my browser data in server will not be removed/deleted until I close comand prompt window..how to delete it? –  ankifreeze Jan 29 '12 at 8:12
add comment

1 Answer

First off, I would highly recommend against using the setInterval overload you are using that takes an eval string. Instead, always use the version that takes a callback. For example:

setInterval(1000, function () {
  // do something

Take a look at the source and you will see that messages are stored in the messages array: https://github.com/ry/node_chat/blob/master/server.js

Your function just needs to inspect this array and remove messages whose timestamp is older than your desired date. For example:

setInterval(1000, function () {
  while (messages.length && messages[0].timestamp < someTime) {

This will keep removing the oldest message while it is older than someTime, which is a time you will need to specify.

share|improve this answer
yes you are right... it does work now...I forgot all messages saved in server.js.....thank you very much... –  ankifreeze Jan 31 '12 at 7:33
@ankifreeze If this is right, would you mind accepting the response as the correct answer? That will resolve this question. –  Rohan Singh Feb 1 '12 at 12:38
add comment

Your Answer


