Home United States USA — software Node.js 15: What's new, what's coming, and keeping pace with Deno. 'We're...

Node.js 15: What's new, what's coming, and keeping pace with Deno. 'We're not going to reinvent' module ecosystem

207
0
SHARE

Michael Dawson, chair of Node.js Technical Steering Committee, talks to The Reg
Interview Popular open-source JavaScript runtime Node.js hit version 15 last week, and to bring us up to date we spoke to Michael Dawson, Red Hat Node.js lead, who is also chair of the Node.js Technical Steering Committee and Community Director of the OpenJS Foundation. So what’s new in Node.js 15? One thing is what happens when an async function fails and throws an error outside a catch block. In the past, Node gives an UnhandledPromiseRejectionWarning but the process exits with a success code. This has changed so that it will now fail with ERR_UNHANDLED_REJECTION. « Unhandled rejections can lead to problems that are very difficult to figure out, » said Dawson. « This will let developers find them much more easily because your Node project will stop running right, and that’s something that you’re going to notice. » The trade-off is that an application that has been stable for years might now fall over. « That’s why we were careful to make sure that it’s very easy to add a very small amount of code and get back up and running, » said Dawson. Node.js uses the same JavaScript engine as the Chromium project, called V8. This has its own native API, and developers may want to call this API from native add-ons for performance or to support additional features. « Back in 2016 we started working on what we call N-API, which is an API that helps you build your native add-ons, » Dawson explained. « Previously you had to use the V8 APIs directly, so in every release of Node which includes a new version of V8, developers would have to update their code. N-API provides a stable API that you can compile against. » Version 15 has an updated N-API. « It brings a couple more methods that help you work with buffers, » Dawson said. « N-API doesn’t have 100 per cent coverage of the V8 APIs, more like 80-90 per cent. So this release brings some progress, though we never plan to provide complete coverage. » There are other options for native code, including FFI (Foreign Function Interface) and WebAssembly. « WebAssembly isn’t necessarily a replacement for N-API, » Dawson said. « There’s different use cases where you’d want to use one versus the other. WebAssembly provides a strong sandbox, but along with that comes some limitations. » In future, he would like to see the compiler handle some of these choices. « You could have code that you can compile to WebAssembly if it uses the subset of the APIs, » he said, « or if it doesn’t, you compile it to N-API, and that changes over time. » The Node team is aware of Deno, a new server-side JavaScript platform co-authored by Ryan Dahl, who also created Node.js and now says that Deno fixes many of its problems.

Continue reading...