Registry / http-networking / traveltime-api

traveltime-api

JSON →
library7.3.3jsnpmunverified

The TravelTime API SDK for Node.js (current stable version 7.3.3) provides a robust interface for interacting with the TravelTime API. This SDK is designed for TypeScript projects, offering type safety and comprehensive autocomplete. Its primary function is to enable developers to find locations and calculate travel times based on journey time rather than traditional 'as the crow flies' distance, facilitating more relevant and personalized spatial search applications. The library sees frequent updates, including regular CVE patching and minor feature enhancements, ensuring a stable and secure development experience. It differentiates itself by focusing on realistic travel time calculations across various transport modes, crucial for logistics, real estate, and urban planning applications.

npm install traveltime-api
INSTALL
IMPORT
SIG · TRAVELTIME-API
T
traveltime-api
http-networkingjavascriptv7.3.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TravelTimeClient
import { TravelTimeClient } from 'traveltime-api';
const TravelTimeClient = require('traveltime-api').TravelTimeClient;
The library primarily uses ES Module (ESM) imports. While CommonJS might work with specific transpilation setups, direct `require` of named exports is generally incorrect in a modern Node.js context.
TimeMapRequestDepartureSearch
import { TimeMapRequestDepartureSearch } from 'traveltime-api';
import TravelTimeClient, { TimeMapRequestDepartureSearch } from 'traveltime-api';
Ensure correct named import; this package does not provide a default export. Avoid syntax implying a default export if none exists.
TravelTimeClientOptions
import { TravelTimeClientOptions } from 'traveltime-api';
This is a type import for configuring the client. It's useful for advanced TypeScript usage to ensure type safety when defining client options.

Demonstrates how to initialize the TravelTimeClient with API keys and rate limit settings, then performs a basic `timeMap` departure search request for a location in London, logging the successful response or any errors.

import { TravelTimeClient, TimeMapRequestDepartureSearch } from 'traveltime-api'; // Initialize the client with your TravelTime API credentials // It is highly recommended to use environment variables for sensitive data. const travelTimeClient = new TravelTimeClient({ apiKey: process.env.TRAVELTIME_API_KEY ?? 'YOUR_APP_KEY_HERE', applicationId: process.env.TRAVELTIME_APP_ID ?? 'YOUR_APP_ID_HERE', // Enable rate limiting to prevent hitting API usage limits rateLimitSettings: { enabled: true, hitsPerMinute: 60, // Adjust this based on your plan's HPM retryCount: 3, timeBetweenRetries: 1000 // milliseconds } }); async function fetchTimeMapForTrafalgarSquare() { const departureSearch: TimeMapRequestDepartureSearch = { id: 'public-transport-from-trafalgar', departure_time: new Date().toISOString(), travel_time: 900, // 15 minutes coords: { lat: 51.507609, lng: -0.128315 }, // Trafalgar Square, London transportation: { type: 'public_transport' }, properties: ['is_only_walking'] }; try { // Make an API call to get a TimeMap (isochrone) for the specified search const response = await travelTimeClient.timeMap({ departure_searches: [departureSearch] }); console.log('Successfully retrieved TimeMap data:'); // The actual data payload is nested under the 'data' property of the AxiosResponse console.log(JSON.stringify(response.data, null, 2)); } catch (error: any) { console.error('Error fetching TimeMap:', error.message || error); if (error.response) { console.error('API Error Response:', error.response.data); } } } fetchTimeMapForTrafalgarSquare();
Debug
Known issues
gotchaTo mitigate 'HTTP 429 Too Many Requests' errors, it is strongly recommended to enable and configure the `rateLimitSettings` when initializing `TravelTimeClient`. This feature dynamically retries requests and helps manage API usage according to your plan's Hits Per Minute (HPM) limits.
fix
When creating `TravelTimeClient`, set `rateLimitSettings: { enabled: true, hitsPerMinute: YOUR_PLAN_HPM, retryCount: 3, timeBetweenRetries: 1000 }`. Adjust `hitsPerMinute` to match your TravelTime API plan.
affects: >=7.0.0
gotchaThe SDK undergoes frequent CVE patching and dependency updates, as indicated by recent changelogs. Users should regularly update to the latest patch versions to ensure they benefit from critical security fixes and maintain a secure application environment.
fix
Periodically run `npm update traveltime-api` to get the latest security patches and integrate dependency scanning tools (e.g., Dependabot, Snyk) into your CI/CD pipeline.
affects: >=7.3.1
gotchaAll API calls return a `Promise<AxiosResponse<EndpointResponseType>>`. The actual data payload from the API is always nested under the `data` property of the resolved `AxiosResponse` object, not directly returned by the promise.
fix
Always access the response data via `response.data` after awaiting an API call, e.g., `const result = (await client.someApiCall(params)).data;`.
affects: >=7.0.0
breakingMajor version 7.x introduced significant refactorings, potentially leading to breaking changes in client initialization, API method signatures, and request/response object structures compared to older major versions (e.g., v6.x).
fix
Consult the official TravelTime Node.js SDK documentation and any available migration guides when upgrading from versions prior to 7.0.0 to understand and adapt to updated API patterns.
affects: >=7.0.0
Errors
Common errors & fixes
Error: Request failed with status code 429
Your application has sent too many requests to the TravelTime API within a short period, exceeding your plan's Hits Per Minute (HPM) limit, leading to throttling by the API.
fix
Enable and correctly configure `rateLimitSettings` when initializing your `TravelTimeClient` instance. Set `enabled: true`, provide your `hitsPerMinute` value, and optionally adjust `retryCount` and `timeBetweenRetries`.
TypeError: Cannot read properties of undefined (reading 'TravelTimeClient')
This error typically occurs when attempting to use CommonJS `require` syntax to import the `TravelTimeClient` class, which is a named export in an ES Module (ESM) oriented package.
fix
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json` for Node.js) and use `import { TravelTimeClient } from 'traveltime-api';`. If bound to CommonJS, consider using a transpiler (e.g., Babel, TypeScript with `moduleResolution: 'node'` and `module: 'CommonJS'`) or adjust your import strategy.
Error: Missing Application ID or API Key. Please provide both.
The `TravelTimeClient` constructor was called without providing valid `applicationId` or `apiKey` credentials.
fix
Pass your `applicationId` and `apiKey` (obtained from the TravelTime Developer Portal Dashboard) as part of the client configuration object: `new TravelTimeClient({ applicationId: 'YOUR_APP_ID', apiKey: 'YOUR_APP_KEY' })`. Always use environment variables for these sensitive credentials.
Upgrade
Version history
7.3.3latest on npm
Audit
Dependencies
axiosoptionalThe SDK leverages Axios internally for HTTP requests, and its types (AxiosResponse) are exposed in the API; a custom Axios instance can also be provided.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources