The library is designed for server-side Node.js applications. You can import the Client using ES6 modules (TypeScript) or CommonJS. Methods take an object containing params, timeout, and optionally headers or an axiosInstance. Note that the API key is configured within the params object of each method call, rather than at the client instantiation level.
import {Client} from "@googlemaps/google-maps-services-js";
const client = new Client({});
client
.elevation({
params: {
locations: [{ lat: 45, lng: -110 }],
key: process.env.MAPS_API_KEY,
},
timeout: 1000, // milliseconds
})
.then((r) => {
console.log(r.data.results[0].elevation);
})
.catch((e) => {
console.log(e.response.data.error_message);
});