What Is New in Node.js 5?
| Category | Change |
|---|---|
| New Features | npm 3 bundled (flat node_modules layout) |
| New Features | V8 4.6 -- spreading arguments in function calls |
| Improvements | Buffer: Buffer.prototype.indexOf() added |
| Improvements | fs: fs.watch() reliability improvements |
| Improvements | Strict mode for the REPL |
| Improvements | net: allow host option to be an IP |
| Security | OpenSSL 1.0.2d |
npm 3 -- Flat Dependency Layout
Node.js 5 bundles npm 3, which changes the node_modules layout from a deeply nested tree to a flat structure. This resolves Windows path length limitations and reduces module duplication -- the same package version is hoisted to the root node_modules where possible.
The trade-off: npm 3 installs are slower due to the additional dedupe analysis step. npm 4 (Node.js 7) and npm 5 (Node.js 8) address speed progressively.
Spread in Function Calls via V8 4.6
V8 4.6 enables spread syntax in function calls. This replaces the verbose Function.prototype.apply() pattern for passing arrays as function arguments.
// Before spread
Math.max.apply(null, [1, 2, 3, 4]); // 4
// With spread (Node.js 5+)
Math.max(...[1, 2, 3, 4]); // 4
function logAll(...args) {
args.forEach(a => console.log(a));
}
logAll('a', 'b', 'c');
Buffer.indexOf() for Binary Search
Buffer.prototype.indexOf() lets you search for a string, byte, or another Buffer within a Buffer without converting to a string first. Useful for parsing binary protocols where you need to find a delimiter sequence.
const buf = Buffer.from('Hello World');
buf.indexOf('World'); // 6
buf.indexOf(0x57); // 6 (ASCII 'W')
FAQ
Is Node.js 5 an LTS release?
No. Node.js 5 is a Current release that reached end-of-life in June 2016. The concurrent LTS was Node.js 4.
Why is npm 3's flat layout important?
Windows has a maximum path length of 260 characters. The nested node_modules layout of npm 2 regularly exceeded this for deeply nested packages, causing failures on Windows that did not occur on macOS or Linux. The flat layout makes Node.js projects reliably cross-platform.
Is V8 4.6 a significant V8 version?
It starts implementing more ES6 features in stages. Spread in calls is one piece. Arrow functions, let/const, and template literals were already available in earlier versions. Full ES6 coverage completes across Node.js 6-8.
Does Buffer.indexOf() handle multi-byte search patterns?
Yes. You can search for a Buffer (e.g., a byte sequence Buffer.from([0xDE, 0xAD])) and it returns the first offset where the sequence begins.
What is the Node.js 5 REPL strict mode?
The REPL can be started with node --use_strict, which runs all REPL input in strict mode. Useful for catching silent errors (undeclared variables, duplicate parameters) during exploratory development.