Is there a way to prevent certain IP to connects with my Node.js ('net') server?

Im using a very basic script of a server with node.js and Net module... Im receiving suspicious connection from IP. I can add all ips that I dont want connected... Its automatic: When the user dont auth, I push his IP into an array and close the socket. If he reconnect Im verifying if his IP is in the array, if true, I close socket again. How to verify this black-list-array before that IP connects to the server? What is the way?

The ideal solution would be to block the IP before it gets to Node.js. Or at least have Linux block it - see this for an example.

But to answer your specific question, you can do something like this:

var http = require('http');

http.createServer(function (req, res) {

    var request_ip = req.ip 
            || req.connection.remoteAddress 
            || req.socket.remoteAddress 
            || req.connection.socket.remoteAddress;

    if (request_ip == '86.75.30.9') // put the IP address here
    {
        // make them wait a bit for a response (optional)
        setTimeout(function() {
            res.end();
        }, 5000);

    }

}).listen(80, '127.0.0.1');