npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@br-health-kit/cnes

v1.0.0

Published

Cliente tipado para a API do CNES (Cadastro Nacional de Estabelecimentos de Saude)

Downloads

165

Readme

@br-health-kit/cnes

A typed client for the CNES API, the Cadastro Nacional de Estabelecimentos de Saúde.

npm install @br-health-kit/cnes
import { cnes } from '@br-health-kit/cnes'

await cnes.findEstablishment('2273993')
await cnes.listEstablishments({ ufCode: 33, limit: 10 })

cnes.isValidCode('2273993')   // offline, syntactic
cnes.normalizeCode(12345)     // '0012345'

Why this package is a client, not a dataset

Every other package in the kit ships its data offline, versioned and reproducible. CNES cannot: the monthly DATASUS dump is 735 MB compressed and covers roughly 380,000 establishments that change every month. Publishing that on npm would be hostile to install and stale within weeks.

So this package owns the shape of the data rather than the data. It maps the government API's 38 snake_case fields, with their nulls, their mixture of numbers and strings, and their inconsistent naming (numero_cnpj next to numero_cnpj_entidade), onto a single typed model, and handles the timeouts and retries that talking to a government server requires.

The consequence, stated plainly: results from this package are not reproducible. They reflect the API at the time of the call. When a result must be pinned, for an audit or a billing batch, record what you received.

Two details that save debugging

Municipality codes have 6 digits, not 7. DATASUS uses the IBGE code without its check digit: Rio de Janeiro is 330455, not 3304557. That is the form the API both returns and accepts as a filter.

Leading zeros are restored. Spreadsheets and JSON turn 0012345 into 12345; normalizeCode undoes that before the call.

Errors

  • code absent from CNES: null, not an exception. It is a normal answer.
  • input that is not a CNES code: InvalidCodeError
  • API unreachable: CnesRequestError, after retry with backoff
  • 404 is not retried; 5xx and network failures are

Tests and the network

The client takes an injected fetch, so your suite does not have to depend on a government server being up:

const client = cnes.client({ fetch: myStub, baseUrl: 'http://localhost:1234' })

Environment

Node 20+, and any browser, through the same entry. There is no /web subpath here because there is no local data to inject: this package is an API client.

Mind CORS, though. The Ministry of Health API is not built to be called from a browser, so in practice you usually want a proxy on your own backend, which is also where the injectable fetch and baseUrl come in handy.

Provenance

Ministry of Health data via apidadosabertos.saude.gov.br. Code under MIT.