Node.js og TypeScript-eksempel på opslag i CVR via CVRcheck API. Async/await, fetch, fejlhåndtering og typesikker JSON-parsing.
const cvr = "28271026"; // Novo Nordisk
const res = await fetch(`https://api.cvrcheck.dk/v1/company/${cvr}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const company = await res.json();
console.log(company.name, company.status);
const headers = { Authorization: `Bearer ${process.env.CVRCHECK_API_KEY}` };
const financials = await fetch(`https://api.cvrcheck.dk/v1/financials/${cvr}`, { headers }).then(r => r.json());