# Build a mileage app in 50 lines of code

> Step-by-step tutorial using the official JavaScript SDK and Express.

**Author:** Camila Ribeiro — Field Operations Editor  
**Published:** 2026-05-02  
**Updated:** 2026-05-02  
**URL:** https://quilometragem.com/blog/build-a-mileage-app-in-50-lines-of-code

**TL;DR:** Step-by-step tutorial using the official JavaScript SDK and Express.

- We'll build a small app that takes origin, destination, and country, calculates the GPS distance, applies the official rate, and returns a PDF receipt — all in under 50 lines of Node.js.
- Get one at https://quilometragem.com/account/api (free, 1,000 requests per 30-day rolling window).
- In three steps you have a mileage microservice ready to plug into an HR portal, an expense chatbot, or a Slack app.
- Wrap the call in a 24h cache per origin-destination pair to reduce free-tier consumption.

## The goal

We'll build a small app that takes origin, destination, and country, calculates the GPS distance, applies the official rate, and returns a PDF receipt — all in under 50 lines of Node.js.[^irs-2025] The secret ingredient is our official `quilometragem-sdk-js` SDK.

## Prerequisites

Node.js 18+ and an API key. Get one at `https://quilometragem.com/account/api` (free, 1,000 requests per 30-day rolling window).

## Step 1: install dependencies

```
npm init -y
npm install express quilometragem-sdk-js
```

## Step 2: the server

```
import express from 'express';
import { Quilometragem } from 'quilometragem-sdk-js';
const app = express(); app.use(express.json());
const qkm = new Quilometragem({ apiKey: process.env.QKM_API_KEY });

app.post('/quote', async (req, res) => {
  const { origin, destination, country = 'us', employeeName } = req.body;
  const route = await qkm.distance({ origin, destination });
  const r = await qkm.reimbursement({ distanceKm: route.distance, country });
  const receipt = await qkm.receipt({
    employeeName, origin, destination,
    distanceKm: route.distance, ratePerKm: r.ratePerKm,
    currency: r.currency,
  });
  res.json({ distance: route.distance, amount: r.amount,
    currency: r.currency, receiptUrl: receipt.url, hash: receipt.hash });
});
app.listen(3000, () => console.log('http://localhost:3000'));
```

## Step 3: test it

```
QKM_API_KEY=qkm_live_… node server.js
curl -X POST localhost:3000/quote -H 'Content-Type: application/json' \
  -d '{"origin":"San Francisco","destination":"Los Angeles","country":"us","employeeName":"Ada"}'
```

The response carries distance, reimbursement amount, public receipt URL, and SHA-256 hash. That's it. In three steps you have a mileage microservice ready to plug into an HR portal, an expense chatbot, or a Slack app.

## Next step: production

Wrap the call in a 24h cache per origin-destination pair to reduce free-tier consumption. Add an auth middleware so only your internal app can call `/quote`. And monitor the `X-RateLimit-Remaining` header to alert before you hit the monthly cap.

## Sources

- [IRS — Standard Mileage Rates for 2025](https://www.irs.gov/tax-professionals/standard-mileage-rates) — Internal Revenue Service (2026-04-28)
