Using TomTom APIs with Node.js and TypeScript

Robert Nash
2 min readJun 9, 2022

The TomTom SDK https://www.npmjs.com/package/@tomtom-international/web-sdk-services provides access to a range of navigation and mapping related services available as part of the TomTom APIs. This can be used for many different tasks such as calculating a route between points.

Unfortunately, using the SDK in a Node.js backend application written in TypeScript seems to be needlessly difficult.

To use the SDK in Node.js instead of a browser environment, it is necessary to import from “@tomtom-international/web-sdk-services/dist/services-node.min.js” as described in the documentation https://developer.tomtom.com/maps-sdk-web-js/overview/product-information/downloads#nodejs

import tt from "@tomtom-international/web-sdk-services/dist/services-node.min.js";

Unfortunately, whilst typings are provided in the library, they do not seem to be setup properly for use with the Node.js build. This means that the above import leads to the following error:

Could not find a declaration file for module ‘@tomtom-international/web-sdk-services/dist/services-node.min.js’.

The easiest way I found to fix this problem was to add a module declaration inside my project.

I created a file called web-sdk-services.d.ts which uses the existing types provided in @tomtom-international\web-sdk-services\dist\index.d.ts and declares the module @tomtom-international/web-sdk-services/dist/services-node.min.js. Having done this the library was now imported properly with types.

It is important that this file is picked up by TypeScript. This could require modifying the include statement in your tsconfig.json file https://www.typescriptlang.org/tsconfig#include. I placed my file inside a types folder in the root of my project but the best location may depend on your particular directory structure.

I am very interested to hear from anyone who finds a better way of getting this to work!

--

--

Robert Nash
0 Followers

I build new products and companies with technologies including React and React Native, Python and Node.js.