Loop through code while listening for socket.io message

I have a page that connects to the node.js server and uses socket.io.

  • Q1 - I want to always loop through some code
  • Q2 - I want the page to listen for socket.io messages
  • Q3 - I want them to do both at the same time.

Here's my basic outline...

loop {
  doSomeCodeHere;
}

//socket.io code here (i know this part)

So basically I need both to function at the same time, any suggestions?