How to use esptool-js from Node.js terminal app

jcolebaker
Posts: 75
Joined: Thu Mar 18, 2021 12:23 am

How to use esptool-js from Node.js terminal app

Postby jcolebaker » Mon Apr 20, 2026 9:30 pm

Hi,

We're using Node.js and the Mocha test framework to run automated tests on our ESP32-based device. This has been working well, including using BLE with "web-bluetooth" and serial port access with the "serialport" package.

We want to install factory firmware and carry out other actions such as erasing OTA partition contents. I have written Javascript code to spawn "esptool.exe" with the appropriate options. This partly works but has been quite unreliable and hacky and also requires users to install esptool correctly.

I recently discovered the "esptool-js" package (https://github.com/espressif/esptool-js) and it looks like it might be very useful.

However, it's designed to work interactively in a browser. Is it possible to use "esptool-js" in a terminal app environment (e.g. an automated test run with Mocha)? We would have to be able to supply it with the name of the serial port we want to use (e.g. "COM5" or similar).

I tried the example code, but when it gets to:

Code: Select all

const port = await navigator.serial.requestPort();
I get:

TypeError: Cannot read properties of undefined (reading 'requestPort')

I guess this is because there is no browser and no UI for the user to select a port? Is it possible to pass it the port name we want to use, so it is suitable for automated use?

Who is online

Users browsing this forum: Amazon [Bot], Baidu [Spider], Bing [Bot], Bytespider, Semrush [Bot] and 8 guests