Why check for socket remoteAddress with NodeJS when serving files?

I'm running a webapp using NodeJS. When I first started building this app (about a year ago) I was very new to the world of NodeJS and Web Programming in general, so a lot of my code was copied directly from examples hosted on other sites/tutorials.

However, now that I'm fairly competent with Node, I have a question about something that I just implemented without really understanding.

In my fileserver, I have the statement: if(req.socket.remoteAddress || req.socket.socket.remoteAddress == '127.0.0.1'){ If this check passes successfully, files are returned to the client, otherwise, nothing gets sent. I honestly have no idea what this really checks for, and what purpose it serves.

Could somebody enlighten me as to what this does exactly, and whether or not it is necessary to have in my server logic?

Best,
Sami

PS The reason I ask now is because I've started having occasional errors as follows: TypeError: Cannot read property 'remoteAddress' of undefined