What Is New in Node.js 10?
| Category | Change |
|---|---|
| New Features | V8 6.6 -- async generators, for-await-of, Promise.finally |
| New Features | fs.promises (experimental) -- promise-based fs API |
| New Features | N-API (Native Addon API) promoted to stable |
| Improvements | npm 6 bundled |
| Improvements | Better error messages with error codes |
| Improvements | trace_events module stabilized |
| Security | OpenSSL 1.1.0h (TLS 1.3 draft support) |
| Deprecated | Several undocumented APIs removed |
Async Generators and for-await-of
Async generators (async function*) let you yield values asynchronously over time, and for await...of lets you consume them. This combination is powerful for pagination, streaming APIs, and pipeline processing.
async function* paginate(url) {
let cursor = null;
do {
const res = await fetch(`${url}?cursor=${cursor}`);
const { items, next } = await res.json();
for (const item of items) yield item;
cursor = next;
} while (cursor);
}
for await (const item of paginate('/api/items')) {
process(item);
}
Promise.finally()
Promise.prototype.finally() runs a callback whether the promise fulfilled or rejected -- the async equivalent of a try/catch/finally block. Common use: cleanup after async operations regardless of outcome.
db.connect()
.then(conn => conn.query('SELECT 1'))
.catch(console.error)
.finally(() => db.disconnect()); // always releases the connection
N-API Stable -- Native Addons That Survive Node Upgrades
N-API (now called Node-API) provides a stable ABI for native C/C++ addons. An addon compiled against N-API works across Node.js versions without recompilation, solving a long-standing pain point where every Node.js upgrade broke native packages.
If you maintain native addons (bcrypt, canvas, sharp, etc.) or use them heavily, N-API stability in Node.js 10 is significant -- upgrade cycles become far less disruptive.
Error Codes for Better Error Handling
Node.js 10 adds stable error codes to system errors (e.g., ERR_MODULE_NOT_FOUND, ENOENT). You can now check err.code rather than parsing the error message string, making error handling more robust and locale-independent.
FAQ
Is Node.js 10 an LTS release?
Yes. Node.js 10 (codename "Dubnium") was an LTS release. Support ended April 2021.
Can I use fs.promises in production with Node.js 10?
It is experimental in v10 -- the API could change. For production, use util.promisify(fs.readFile) or the graceful-fs package which has a stable promise interface. fs.promises stabilizes in Node.js 14.
Does N-API eliminate the need for nan (Native Abstractions for Node)?
Yes, for new addons. N-API is the recommended way to write native addons. nan still works but is a compatibility layer that requires recompilation per Node version -- exactly what N-API avoids.
Are async generators lazy or eager?
Lazy. A generator does not execute until you start consuming it with for await...of or .next(). Values are produced on demand, which makes them memory efficient for large data sequences.
What npm version does Node.js 10 ship with?
npm 6.x. npm 6 added npm audit for security vulnerability scanning, which became an important tool for supply chain security reviews.