Gabotronix
1 month ago

Using google places API in node.js server enviroment

Posted 1 month ago by Gabotronix

Hi everybody, this is my first node.js application where I will be using javascript in the server, previously I used google places API javascripe in the client, like this:

async codeAddressFromList(address)
    {
        const self = this;
        this.address = address;
    
        return self.geocoderService.geocode( { 'address': address}, function(results, status)
        {
            if (status == 'OK')
            {
                self.map.setCenter(results[0].geometry.location);
                self.calculateNewSquareVertex(results[0].geometry.location);
                self.drawRects();
            } 
            else
            {
                alert('Geocode was not successful for the following reason: ' + status);
            }
        });
    },

I was wondering what's the best way to use google places API in node.js.

Since node is javascript in the server will I be able to use the javascript API in the server? I have seen some people using axios to make requests and using query strings, I have also found about this library:

https://github.com/googlemaps/google-maps-services-js

But I'm not sure about suing a lib, what is the more vanilla, battle tested way to do this?

Can you guys post some of your node.js google places API examples?

Please sign in or create an account to participate in this conversation.