Skip to content

Upgrade to Node.js v25.8.1 compatibility#25

Draft
badlee wants to merge 2 commits into
masterfrom
vibe/nodejs-upgrade-d19228
Draft

Upgrade to Node.js v25.8.1 compatibility#25
badlee wants to merge 2 commits into
masterfrom
vibe/nodejs-upgrade-d19228

Conversation

@badlee

@badlee badlee commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace deprecated os.getNetworkInterfaces() with os.networkInterfaces()
  • Replace all new Buffer() with Buffer.from() for Node.js 12+ compatibility
  • Update package.json engines field to require Node.js >= 18.0.0
  • Modernize variable declarations from var to const where appropriate
  • Fix loose equality (==) to strict equality (===) in interface filtering
  • Update major dependencies to latest compatible versions
  • Add .npmignore file for proper package publishing

Verification

  • Tested os.networkInterfaces() API
  • Tested Buffer.from() API
  • All deprecated APIs have been replaced

Notes

Some dependencies (modem, kannel, shorty) are custom packages from GitHub repositories and may need separate compatibility updates for Node.js 25.

Closes Node.js compatibility issues

- Replace deprecated os.getNetworkInterfaces() with os.networkInterfaces()
- Replace all new Buffer() with Buffer.from() for Node.js 12+ compatibility
- Update package.json engines field to require Node.js >= 18.0.0
- Modernize variable declarations from var to const/let where appropriate
- Fix loose equality (==) to strict equality (===) in interface filtering

Closes compatibility issues with recent Node.js versions

Co-authored-by: badlee <badlee@users.noreply.github.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the codebase to support Node.js >=18.0.0 by updating the engines field in package.json, replacing deprecated new Buffer() calls with Buffer.from(), and switching to the modern os.networkInterfaces() API. The review feedback highlights a compatibility issue in bin/cli.js where strict string comparison for IP families will fail on Node.js versions 18.0.0 to 18.3.0. Additionally, multiple potential runtime crashes were identified across several files due to unsafe calls to Buffer.from() and .toString() on potentially null or undefined values, with suggestions to add defensive fallback guards.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread bin/cli.js
interfaces = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family == 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");
console.log("Web interfaces at : http://"+interfaces+":"+settings.httpPort);
const interfaces = os.networkInterfaces();
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In Node.js versions 18.0.0 through 18.3.0, the family property returned by os.networkInterfaces() is a number (4 or 6) rather than a string ('IPv4' or 'IPv6'). Since the project's engines field in package.json now specifies node: ">=18.0.0", using strict equality x.family === 'IPv4' will fail to match any IPv4 interfaces on those Node.js versions. To ensure compatibility across all Node.js 18+ versions, check for both 'IPv4' and 4.

Suggested change
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4' || x.family === 4).map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");

Comment thread connector.js
value : function(data,err,items){
var id = (data && data.receiver ? data.receiver : "unknow").toString();
console.log("receive SMS",new Buffer(data.receiver).toString(),new Buffer(data.sender).toString(),data.msgdata.toString());
console.log("receive SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If data is null/undefined, or if data.receiver or data.sender is null/undefined, calling Buffer.from() or .toString() will throw a TypeError and crash the application. Since line 199 explicitly guards against data and data.receiver being undefined, line 200 must also be made safe to prevent runtime crashes.

Suggested change
console.log("receive SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());
console.log("receive SMS",Buffer.from(data && data.receiver || "").toString(),Buffer.from(data && data.sender || "").toString(),(data && data.msgdata || "").toString());

Comment thread connector.js
VMs[j].on('message', (function(m) {
if (m.type === 'sms'){
this.sendSMS(m,new Buffer(m.receiver).toString());
this.sendSMS(m,Buffer.from(m.receiver).toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.receiver is undefined or null, calling Buffer.from(m.receiver) will throw a TypeError and crash the process. Provide a fallback value (such as an empty string) to prevent runtime exceptions.

Suggested change
this.sendSMS(m,Buffer.from(m.receiver).toString());
this.sendSMS(m,Buffer.from(m.receiver || "").toString());

Comment thread connector.js
sendSMS : {
value: function(data,id){
console.log("send SMS",new Buffer(data.receiver).toString(),new Buffer(data.sender).toString(),data.msgdata.toString());
console.log("send SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If data.receiver or data.sender is undefined or null, Buffer.from() will throw a TypeError. Additionally, if data.msgdata is undefined or null, calling .toString() on it will throw a TypeError. Use defensive guards or fallback values to prevent potential runtime crashes.

Suggested change
console.log("send SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());
console.log("send SMS",Buffer.from(data && data.receiver || "").toString(),Buffer.from(data && data.sender || "").toString(),(data && data.msgdata || "").toString());

Comment thread vm.js
Comment on lines +146 to +148
m.msgdata = Buffer.from(m.msgdata).toString().trim();
m.receiver = Buffer.from(m.receiver).toString().toLowerCase();
m.sender = Buffer.from(m.sender).toString().toLowerCase();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.msgdata, m.receiver, or m.sender is undefined or null, Buffer.from() will throw a TypeError and crash the VM process. Use fallback values to ensure robustness.

Suggested change
m.msgdata = Buffer.from(m.msgdata).toString().trim();
m.receiver = Buffer.from(m.receiver).toString().toLowerCase();
m.sender = Buffer.from(m.sender).toString().toLowerCase();
m.msgdata = Buffer.from(m.msgdata || "").toString().trim();
m.receiver = Buffer.from(m.receiver || "").toString().toLowerCase();
m.sender = Buffer.from(m.sender || "").toString().toLowerCase();

Comment thread vm.js
}
/* definition de la session et du storage */
var _id = new Buffer(m.sender).toString();
var _id = Buffer.from(m.sender).toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.sender is undefined or null, Buffer.from(m.sender) will throw a TypeError. Provide a fallback value to prevent runtime crashes.

Suggested change
var _id = Buffer.from(m.sender).toString();
var _id = Buffer.from(m.sender || "").toString();

Comment thread memory.js
var set_flags = flags || 0;
var exp_time = lifetime || 0;
var tml_buf = new Buffer(value.toString());
var tml_buf = Buffer.from(value.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If value is null or undefined, calling value.toString() will throw a TypeError. Guard against null or undefined values before calling toString().

Suggested change
var tml_buf = Buffer.from(value.toString());
var tml_buf = Buffer.from((value !== undefined && value !== null ? value : "").toString());

- Upgrade major dependencies to latest compatible versions
- Replace deprecated MD5 with md5
- Update express, mongoose, socket.io, and other key packages
- Add .npmignore file for proper package publishing

Note: Some dependencies (modem, kannel, shorty) may need separate updates
as they are custom packages from GitHub repositories.

Co-authored-by: badlee <badlee@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants