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:
time:
17:14
17:12
16:13
15:11
14:17
function del(){
if(time<timenow-1000){delete time;}}
setInterval("del()",10000);
I want to delete data less than two hours ago every one hours using interval time…thanks
First off, I would highly recommend against using the
setIntervaloverload you are using that takes anevalstring. Instead, always use the version that takes a callback. For example:Take a look at the source and you will see that messages are stored in the
messagesarray: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:
This will keep removing the oldest message while it is older than
someTime, which is a time you will need to specify.