Upgrade to Node.js v25.8.1 compatibility#25
Conversation
- 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>
There was a problem hiding this comment.
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.
| 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://"); |
There was a problem hiding this comment.
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.
| 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://"); |
| 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()); |
There was a problem hiding this comment.
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.
| 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()); |
| 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()); |
There was a problem hiding this comment.
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.
| this.sendSMS(m,Buffer.from(m.receiver).toString()); | |
| this.sendSMS(m,Buffer.from(m.receiver || "").toString()); |
| 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()); |
There was a problem hiding this comment.
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.
| 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()); |
| m.msgdata = Buffer.from(m.msgdata).toString().trim(); | ||
| m.receiver = Buffer.from(m.receiver).toString().toLowerCase(); | ||
| m.sender = Buffer.from(m.sender).toString().toLowerCase(); |
There was a problem hiding this comment.
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.
| 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(); |
| } | ||
| /* definition de la session et du storage */ | ||
| var _id = new Buffer(m.sender).toString(); | ||
| var _id = Buffer.from(m.sender).toString(); |
| var set_flags = flags || 0; | ||
| var exp_time = lifetime || 0; | ||
| var tml_buf = new Buffer(value.toString()); | ||
| var tml_buf = Buffer.from(value.toString()); |
There was a problem hiding this comment.
- 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>
Summary
Verification
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