How to get the user IP address in Meteor server?

1 – Without a http request, in the functions you should be able to get the clientIP with:

clientIP = this.connection.clientAddress;
//EX: you declare a submitForm function with Meteor.methods and 
//you call it from the client with Meteor.call().
//In submitForm function you will have access to the client address as above

2 – With a http request and using iron-router and its Router.map function:

In the action function of the targeted route use:

clientIp = this.request.connection.remoteAddress;

3 – using Meteor.onConnection function:

Meteor.onConnection(function(conn) {
    console.log(conn.clientAddress);
});

Leave a Comment