Skip to content

Runnable Node.js example

This client sends one search, prints progressive results, distinguishes text errors from binary results and waits for completion. It supports JSON and Protobuf without guessing frame types.

Install ws and protobufjs in an empty directory. Save plan.mjs under examples/, then save all four schema files under proto/ next to that directory.

my-planner-example/
examples/plan.mjs
proto/PlanRequest.proto
proto/PlanResult.proto
proto/Modes.proto
proto/DirectionType.proto
Terminal window
npm init -y
npm install ws protobufjs

Set your key in the terminal where you run the client:

Terminal window
export INFOPLAZA_API_KEY='YOUR_API_KEY'

Replace YOUR_API_KEY with your Infoplaza API key. The client adds it as the api_key query parameter on wss://api.infoplaza.com/v1/transit/implanner.

Terminal window
node examples/plan.mjs

Protobuf is the default for both the client and the public endpoint. You can also select it explicitly with PLANNER_FORMAT=proto. On the connection URL, the equivalent optional parameter is mode=proto.

The script uses Utrecht Centraal / Science Park and the current time. Fare information and average walking and cycling speeds are included.

This Node.js example loads the schemas at startup. For a browser application, follow Generate TypeScript types to generate the client during development.

Terminal window
PLANNER_FORMAT=json node examples/plan.mjs

The client connects to the same public endpoint with your API key and mode=json.

Each response can contain multiple trips. The script prints times, duration, transfer count, optional fares and replay hashes. It prints routing errors separately and returns a failing process status for connection, decoding or terminal failures. The example times out after 60 seconds.

Download the complete client · Understand the lifecycle · Use a recipe