# CVR Lookup: Node.js example

A small server-side example for looking up a Danish company by CVR number.
Requires Node.js 22 or newer. No npm packages or account needed for the demo.

- [Tutorial](https://cvrlookup.dk/blog/cvr-api-nodejs)
- [API overview and browser demo](https://cvrlookup.dk/cvr-api)
- [Endpoint documentation](https://cvrlookup.dk/dokumentation#company)
- [Download the script](https://cvrlookup.dk/examples/cvr-lookup.mjs)

Download and inspect the script, then run it:

```sh
curl --fail --show-error --output cvr-lookup.mjs https://cvrlookup.dk/examples/cvr-lookup.mjs
node cvr-lookup.mjs
```

With no arguments it always uses the public fixture key and returns synthetic
Testselskabet ApS data (CVR 10000001), even if an API key is set in your environment.
It makes one request, prints JSON to stdout and a test-data notice to stderr.

For a real company, create an API key in the dashboard. Store it in your server's
environment or an uncommitted `.env` file:

```text
CVRLOOKUP_API_KEY=your_own_key
```

```sh
node --env-file=.env cvr-lookup.mjs 43269070
```

Never include the key in client-side JavaScript, a public repository or a support
message. Real lookups use your plan's quota and rate limits. All public plans
support this single-company endpoint; financials use a separate Pro endpoint.

The example handles invalid input, missing credentials, network/timeouts, HTTP
errors and invalid responses. It exits with status 1 on failure and does not retry
automatically. A 429 may be either a per-minute limit or monthly quota exhaustion;
check your usage before retrying. Optional registry fields can be absent: validate
the fields you need before updating customer records.

## License for cvr-lookup.mjs

MIT License

Copyright (c) 2026 codepilots ApS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
