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

scraping-nfce-sefazes

v3.0.1

Published

Webscraping de busca de NFCe

Readme

WebScraping NFCe Sefaz ES

Biblioteca para busca de informações de Nota Fiscal de Consumidor Eletrônica (NFC-e) no site da SEFAZ-ES. Retorna um objeto com os dados da NFC-e, como informações do estabelecimento, consumidor, itens, totalizadores e dados gerais.

Pré-requisitos

  • Node.js: Versão 18 ou superior.
  • Dependências: As dependências são instaladas automaticamente com o pacote. Incluem puppeteer, jimp, moment-timezone e qrcode-reader.

Instalação

Instale a biblioteca usando npm ou pnpm:

npm install @devix-tecnologia/scraping-nfce-sefaz-es
# ou
pnpm install @devix-tecnologia/scraping-nfce-sefaz-es

Uso

Importando a biblioteca

Importe a classe SefazES no seu projeto. A biblioteca suporta ESM e CommonJS:

// ESM (recomendado)
import { SefazES } from "@devix-tecnologia/scraping-nfce-sefaz-es";

// CommonJS
const { SefazES } = require("@devix-tecnologia/scraping-nfce-sefaz-es");

Criando a função de busca

Crie uma função assíncrona para chamar o método buscarNfce. O método aceita um link do QR code da NFC-e ou o caminho de uma imagem contendo o QR code.

async function buscarNota(item) {
  try {
    const { resultadoBusca } = await SefazES.buscarNfce(item);
    return resultadoBusca;
  } catch (erro) {
    console.error("Erro:", erro);
    throw erro;
  }
}

Exemplos de uso

Busca com URL do QR code

const url =
  "http://app.sefaz.es.gov.br/ConsultaNFCe/qrcode?p=08240100813024000129650010000383801000383801|2|1|1|1";

buscarNota(url)
  .then((resultado) => {
    console.log("Resultado:", JSON.stringify(resultado, null, 2));
  })
  .catch((erro) => {
    console.error("Erro:", erro);
  });

Busca com imagem do QR code

const caminhoImagem = "./caminho/para/qrcode.png";

buscarNota(caminhoImagem)
  .then((resultado) => {
    console.log("Resultado:", JSON.stringify(resultado, null, 2));
  })
  .catch((erro) => {
    console.error("Erro:", erro);
  });

Estrutura do resultado

O método buscarNfce retorna um objeto com a seguinte estrutura:

{
  resultadoBusca: {
    estabelecimento: {
      nome: string,
      cnpj: number,
      endereco: string
    },
    consumidor: {
      cpf?: number,
      nome?: string,
      logradouro?: string
    },
    infoGerais: {
      emissaoTipo?: string,
      numero?: number,
      serie?: number,
      emitidaEm?: string,
      protocolo?: number,
      chave?: string
    },
    listaItens: [
      {
        nome: string,
        codigo: number,
        quantidade: number,
        unidade: string,
        valorUnitario: number,
        valorTotal: number
      }
    ],
    totalizadores: {
      qtdTotalItens?: number,
      valorPagar?: number,
      descontos?: number,
      valorTotal?: number,
      tributos?: number
    }
  }
}

Desenvolvimento

Para rodar o projeto localmente (por exemplo, para testes ou desenvolvimento):

  1. Clone o repositório:
git clone <URL_DO_REPOSITORIO>
cd scraping-nfce-sefaz-es
  1. Instale as dependências:
pnpm install
  1. Execute o build para compilar a biblioteca:
pnpm run build
  1. Execute o script de teste:
pnpm start

O script de teste (index.js) está configurado para buscar uma NFC-e de exemplo. Edite o arquivo index.js para testar com outras URLs ou imagens.

Notas

  • Puppeteer: Requer o Chromium, que é instalado automaticamente com o puppeteer. Certifique-se de ter espaço suficiente e permissões adequadas.
  • Imagens: A leitura de QR codes depende da biblioteca qrcode-reader. Certifique-se de que as imagens fornecidas sejam claras e contenham um QR code válido.
  • Ambiente: Testado com Node.js 20.12.2. Outras versões podem requerer ajustes.

Contribuidores