A web page should never hold your API key: anyone can read it. This guide puts the key in a small Node.js server, which asks Nimbo for the rain and passes the answer on to the browser.
Before you start
You need a key: get one free, no card. Put it in an environment variable: export NIMBO_KEY=nimbo_...
You also need Node.js 18 or newer. Install our library with npm install nimbo-weather, or install nothing at all: plain HTTP uses the built-in fetch.
With our JavaScript library
The quickest way, on a server or in a script: our client library, with types, timeouts and retries on rate limits: nimbo-weather on npm, no dependencies, TypeScript types included. It reads the key from NIMBO_KEY (or NIMBO_API_KEY).
npm install nimbo-weatherimport { Nimbo } from "nimbo-weather";
const nimbo = new Nimbo();
const forecast = await nimbo.nowcast(48.86, 2.35); // Paris
console.log(forecast.summary?.text ?? "No radar coverage at this point");
for (const m of forecast.minutely.slice(0, 6)) console.log(m.time, m.precip_mm_h);The source is on GitHub. Keep it on the server, like any code that holds your key.
Without the library: one call with fetch
The same call in plain HTTP, for a script or a serverless function:
const res = await fetch("https://nimboweather.com/v1/nowcast?lat=48.86&lon=2.35", {
headers: { "X-API-Key": process.env.NIMBO_KEY },
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error}: ${data.message}`);
console.log(data.summary?.text ?? "No radar coverage at this point");Save it as rain.mjs (the .mjs ending allows await at the top) and run node rain.mjs.
The complete example: server and browser
Save this as server.mjs, run node server.mjs and open http://localhost:3000. The browser asks for the visitor’s location, calls /rain on your server, and your server calls Nimbo with the key.
// server.mjs: node server.mjs, then open http://localhost:3000
import { createServer } from "node:http";
const BASE = "https://nimboweather.com";
const KEY = process.env.NIMBO_KEY; // stays on the server
const cache = new Map(); // "lat,lon" -> { at, body }
async function nowcast(lat, lon) {
// round to about 1 km: nearby visitors share one call, and the exact place is never sent on
const id = `${lat.toFixed(2)},${lon.toFixed(2)}`;
const hit = cache.get(id);
if (hit && Date.now() - hit.at < 5 * 60_000) return hit;
const res = await fetch(`${BASE}/v1/nowcast?lat=${lat.toFixed(2)}&lon=${lon.toFixed(2)}&horizon=120`, {
headers: { "X-API-Key": KEY },
});
const entry = { at: Date.now(), status: res.status, body: await res.text() };
if (res.ok) cache.set(id, entry);
return entry;
}
createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost");
if (url.pathname === "/rain") {
const lat = Number(url.searchParams.get("lat"));
const lon = Number(url.searchParams.get("lon"));
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
res.writeHead(400).end("lat and lon required");
return;
}
const { status, body } = await nowcast(lat, lon);
res.writeHead(status, { "Content-Type": "application/json" }).end(body);
return;
}
res.writeHead(200, { "Content-Type": "text/html" }).end(PAGE);
}).listen(3000);
const PAGE = `<!doctype html>
<meta charset="utf-8">
<p id="rain">Finding you...</p>
<script>
const out = document.getElementById("rain");
navigator.geolocation.getCurrentPosition(async ({ coords }) => {
const res = await fetch("/rain?lat=" + coords.latitude + "&lon=" + coords.longitude);
const data = await res.json();
if (res.status === 404) out.textContent = "Outside the forecast area.";
else if (!res.ok) out.textContent = "No forecast right now (" + data.error + ").";
else if (!data.summary) out.textContent = "No radar sees this place.";
else out.textContent = data.summary.text + (data.stale ? " (radar data is late)" : "");
}, () => { out.textContent = "Location not shared."; });
</script>`;The server rounds each location to about 1 km and keeps answers for 5 minutes, so many visitors in one town cost one call, and your visitors’ exact positions never leave your server. The forecast itself changes every 10 minutes.
What the browser gets
The answer passes through unchanged. The summary is usually all a page needs:
| Field | Meaning |
|---|---|
summary.text | A sentence in English, ready to show: “No rain expected in the next 3 hours”, “Light rain, stopping in about 30 min”. |
summary.rain_now | true when it is raining at the point now. |
summary.rain_starts_at, summary.rain_ends_at | Start and end of the first shower (UTC), or null. |
summary.max_intensity | Peak of the first shower: light, moderate, heavy or violent. Handy for an icon. |
stale, notice | The radar data is late; notice says since when during an outage. |
minutely | Rate and chance of rain every 5 minutes, to draw a small chart (here 2 hours, from horizon=120). |
Common pitfalls
- A key in the page.
Authorization: Bearerworks from a browser too, which is fine for a prototype, but anyone can copy a key from a page. If that happens, regenerate it from your dashboard: the old one stops at once, your plan stays. - Cached sentences age.
summary.textcounts from the moment of the request (“in 27 min”). If you cache longer than a few minutes, count the minutes yourself fromrain_starts_at. - Two kinds of “no forecast”. Outside Europe’s grid the API answers
404 out_of_coverage; inside it, where no radar sees, a200withcoverage: "no_radar"andsummary: null. The example handles both. - Null rates. With
no_radar, everyprecip_mm_hisnull:Math.max(...rates)needs a filter first. - Outages and limits.
503 forecast_unavailableafter 2 hours without radar (try again in 10 minutes);429 monthly_quota_exceededwhen the month’s allowance is used. The server above does not cache errors. - Times are UTC. Every time ends in
Z;new Date(t).toLocaleTimeString()shows it in the visitor’s own time.