This.connection is always undefined on server side


My code is as the following:

if (Meteor.isServer) {
  const geoip2 = require('geoip2');

    'getGeoInfo'() {
      const ip = this.connection.clientAddress;
      return geoip2.lookupSimpleSync(ip);

It always prints undefined, why ?


I don’t know - that should work. What version of Meteor are you using?

Also, where are you calling your method from? If it’s called within the server code it will return null (so, not undefined).


I’m using Meteor, and I call this method from client, the client code is as follows:

componentDidMount() {'getGeoInfo', (error, result) => {
      if (error) {
      }  else {
        this.setState({address: + ", " + result.subdivision + ", " +
 + " " + result.postal});


Now I have figured out why. Actually my code works if I deploy my web App to a server with a public IP, for example an AWS E2 instance with Elastic IP.

If I run it locally on my Macbook while development, then the connection is always null.


Today I have the same problem. Thank you for sharing “solution”.