Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Cannot read properties of null (reading 'on')

Open
#386 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
backend

Research direction

Reproduce the failure by sending a second POST to /print in server.js, then inspect escpos-network/index.js at Network.open line 30 and the call from server.js line 37. Trace the network socket lifecycle through device.open and the printer close call; done means successive print requests no longer throw the null .on error.

Written by the indexing model from the issue text.

Description

Hi, I have a problem, when I start the server with this code

`'use strict';
const path = require('path')
const escpos = require('escpos')
escpos.Network = require('escpos-network');

const device = new escpos.Network('192.168.1.200', 9100);
const options = { encoding: "GB18030" }
const printer = new escpos.Printer(device)






var bodyParser = require('body-parser')
var app = require('express')()
var http = require('http').Server(app)
var cors = require('cors')
app.use(cors())
app.use(bodyParser.json())

const port = 4000;

app.post('/print', (req, res) => {
  res.json(
    { status: 'success' }
  )
  console.log(req.body)
  print(req.body.text)
});

http.listen(port, () => {
  console.log(`Printer: http://localhost:${port}`);
});

const print = (text) => {
  device.open(function () {
    printer
      .font('a')
      .align('ct')
      .style('bu')
      .size(3, 3)
      .text(text)
      .cut()
      .close();
  });
}
`

I can only do one print after which if I try to do another print I have this problem

TypeError: Cannot read properties of null (reading 'on') at Network.open (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\escpos-network\index.js:30:15) at print (C:\Users\matti\Downloads\node-escpos-3\examples\web\server.js:37:10) at C:\Users\matti\Downloads\node-escpos-3\examples\web\server.js:29:3 at Layer.handle [as handle_request] (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\route.js:144:13) at Route.dispatch (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\route.js:114:3) at Layer.handle [as handle_request] (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\layer.js:95:5) at C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\index.js:286:22 at Function.process_params (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\index.js:348:12) at next (C:\Users\matti\Downloads\node-escpos-3\examples\web\node_modules\express\lib\router\index.js:280:10)

Please could you help me solve this problem, I can't seem to figure it out!

Dominant language
TypeScript
Stars
1.6k
Forks
443
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lsongdev/node-escpos

All issues in lsongdev/node-escpos

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.