Top 10 Must‑Know Node.js v6 Features Over v4
Node.js v6 introduces a suite of powerful enhancements over v4, including integrated Chrome DevTools debugging, EventEmitter event introspection, revamped Buffer APIs, unhandled Promise rejection warnings, secure temporary directory creation, symlink preservation, process warning handling, timing-safe crypto, V8 profiling shortcuts, and detailed CPU usage reporting.
Node.js v6 is now LTS, while v7 is current. Let’s look at the features in Node v6 compared to v4 that are worth noting.
1. Integrated Chrome DevTools
Run node --inspect --debug-brk file.js and a debug URL is printed; open it in Chrome to use familiar DevTools for debugging Node code, with live code editing and full asynchronous call stacks.
2. Retrieve all event names from an EventEmitter instance
Calling emitter.eventNames() lists all event names that the emitter is listening to.
const EventEmitter = require('events');
const ee = new EventEmitter();
ee.on('foo', () => {});
ee.on('bar', () => {});
console.log(ee.eventNames()); // ['foo', 'bar']3. Revised Buffer constructor API
The old new Buffer() constructor is deprecated because its behavior can be error‑prone. Use the clearer APIs: Buffer.from(): creates a Buffer from a string, array, or existing Buffer. Buffer.alloc(): allocates a Buffer of a given size, zero‑filled.
4. Warning for unhandled Promise rejections
In earlier Node versions an unhandled rejection emitted an unhandledRejection event on process. In v6 a warning is shown directly.
$ node
> new Promise((resolve, reject) => { setTimeout(() => { reject(new Error('Whoa!')) }, 100) })
Promise { <pending> }
> (node:35449) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Whoa!5. Fast and safe creation of temporary directories
Use the native fs.mkdtemp(prefix) method, which appends a 6‑character random string to the prefix.
fs.mkdtemp('/tmp/foo-', (err, folder) => {
if (err) throw err;
console.log(folder); // -> /tmp/foo-itXde2
});6. Preserve symbolic links
This feature affects how require resolves modules. Without preserving symlinks, a module may break because Node resolves the real path.
- app
- index.js // require('dep1')
- node_modules
- dep1 -> ../../mods/dep1
- dep2 -> ../../mods/dep2
- mods
- dep1
- index.js // require('dep2') -> break!
- dep2
- index.jsv6 adds the CLI option --preserve-symlinks to change this behavior, but use it cautiously as it can break many modules.
7. New process warning API
You can now listen for process warnings with process.on('warning', (warning) => {}) and emit a warning via process.emitWarning('something'), which is useful for logging.
8. Prevent timing attacks
The new crypto.timingSafeEqual() method helps avoid timing attacks.
9. Directly view V8 performance profiling reports
Run node --prof bench.js to generate a V8 log, then use node --prof-process isolate-0x...-v8.log to obtain a readable report.
10. CPU time
The new process.cpuUsage() interface returns user and system CPU time.
const usage = process.cpuUsage(); // { user: 38579, system: 6986 }Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Node Underground
No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
