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

printer-electron-node

v1.6.2

Published

Node.js and Electron bindings

Readme

printer-electron-node

Node.js e Electron bindings para gerenciamento e impressão direta em impressoras. Suporta Windows e Linux (CUPS).

Características

  • Listar todas as impressoras disponíveis
  • Obter impressora padrão do sistema
  • Obter status detalhado da impressora
  • Impressão direta (raw printing)
  • Suporte a TypeScript
  • API assíncrona (Promises)
  • Compatível com Node.js e Electron

Requisitos

  • Node.js >= 18.20.6
  • Electron >= 20.0.0
  • Windows ou Linux
  • Para Windows: Visual Studio Build Tools
  • Para Linux: CUPS development headers (sudo apt-get install libcups2-dev)

Instalação

npm install printer-electron-node

Para desenvolvimento:

git clone https://github.com/Alexssmusica/printer-electron-node.git
cd printer-electron-node
npm install
npm run rebuild

Uso

JavaScript

const printer = require('printer-electron-node');

// Listar todas as impressoras
printer.getPrinters()
  .then(printers => {
    console.log('Impressoras disponíveis:', printers);
  })
  .catch(console.error);

// Obter impressora padrão
printer.getDefaultPrinter()
  .then(defaultPrinter => {
    console.log('Impressora padrão:', defaultPrinter);
  })
  .catch(console.error);

// Verificar status de uma impressora
printer.getStatusPrinter({ printerName: 'Nome da Impressora' })
  .then(status => {
    console.log('Status da impressora:', status);
  })
  .catch(console.error);

// Imprimir diretamente
const printOptions = {
  printerName: 'Nome da Impressora',
  data: 'Texto para impressão',
  dataType: 'RAW'  // opcional, padrão é 'RAW'
};

printer.printDirect(printOptions)
  .then(result => {
    console.log('Resultado:', result);
  })
  .catch(console.error);

TypeScript

import printer, { 
  Printer, 
  PrintDirectOptions, 
  GetStatusPrinterOptions 
} from 'printer-electron-node';

async function exemplo() {
  try {
    // Listar impressoras
    const printers: Printer[] = await printer.getPrinters();
    console.log('Impressoras:', printers);

    // Obter impressora padrão
    const defaultPrinter: Printer = await printer.getDefaultPrinter();
    console.log('Impressora padrão:', defaultPrinter);

    // Verificar status
    const statusOptions: GetStatusPrinterOptions = {
      printerName: 'Nome da Impressora'
    };
    const status: Printer = await printer.getStatusPrinter(statusOptions);
    console.log('Status:', status);

    // Imprimir
    const printOptions: PrintDirectOptions = {
      printerName: 'Nome da Impressora',
      data: Buffer.from('Texto para impressão'),
      dataType: 'RAW'
    };
    const result = await printer.printDirect(printOptions);
    console.log('Resultado:', result);
  } catch (error) {
    console.error('Erro:', error);
  }
}

API

getPrinters(): Promise<Printer[]>

Lista todas as impressoras instaladas no sistema.

Retorna um array de objetos Printer:

interface Printer {
    name: string;
    isDefault: boolean;
    status: string;
    details: {
        location?: string;
        comment?: string;
        driver?: string;
        port?: string;
        [key: string]: string | undefined;
    };
}

getDefaultPrinter(): Promise

Obtém a impressora padrão do sistema.

Retorna um objeto Printer.

getStatusPrinter(options: GetStatusPrinterOptions): Promise

Obtém o status detalhado de uma impressora específica.

interface GetStatusPrinterOptions {
    printerName: string;
}

printDirect(options: PrintDirectOptions): Promise

Envia dados diretamente para a impressora.

interface PrintDirectOptions {
    printerName: string;
    data: string | Buffer;
    dataType?: 'RAW' | 'TEXT' | 'COMMAND' | 'AUTO';
}

Valores possíveis para status:

  • "ready": impressora pronta
  • "offline": impressora offline
  • "error": erro genérico
  • "paper-jam": papel atolado
  • "paper-out": sem papel
  • "manual-feed": alimentação manual
  • "paper-problem": problema com papel
  • "busy": ocupada
  • "printing": imprimindo
  • "output-bin-full": bandeja de saída cheia
  • "not-available": não disponível
  • "waiting": aguardando
  • "processing": processando
  • "initializing": inicializando
  • "warming-up": aquecendo
  • "toner-low": pouco toner
  • "no-toner": sem toner
  • "page-punt": problema na página
  • "user-intervention": necessita intervenção do usuário
  • "out-of-memory": sem memória
  • "door-open": porta aberta

Plataformas Suportadas

  • Windows (32/64 bits)
  • Linux (CUPS)

Troubleshooting

Windows

  1. Certifique-se de ter o Visual Studio Build Tools instalado
  2. Execute npm run rebuild após a instalação
  3. Verifique as permissões de acesso às impressoras

Linux

  1. Instale as dependências do CUPS: sudo apt-get install libcups2-dev
  2. Verifique se o serviço CUPS está rodando: sudo service cups status
  3. Verifique as permissões do usuário: sudo usermod -a -G lp $USER

Desenvolvimento

# Clonar o repositório
git clone https://github.com/Alexssmusica/printer-electron-node.git

# Instalar dependências
npm install

# Compilar
npm run rebuild

# Executar testes
node teste.js

Licença

MIT

Contribuindo

  1. Fork o projeto
  2. Crie sua Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit suas mudanças (git commit -m 'Add some AmazingFeature')
  4. Push para a Branch (git push origin feature/AmazingFeature)
  5. Abra um Pull Request

Changelog

1.0.0

  • Implementação inicial
  • Suporte a Windows e Linux
  • API básica de impressão e gerenciamento de impressoras

Autor

Alex Santos de Souza - @Alexssmusica

Agradecimentos

  • Node.js
  • node-addon-api
  • CUPS