This week, we saw the release of Node.js v12, the next Node.js release line that will become LTS. I wanted to go through the various posts that went out and the changelog and condense the information into an easily consumable digest of what's new in Node.js v12.x to share with everyone. 💖
Let's dig into some of the most important and remarkable changes that have landed in v12.0.0!
With the release of Node.js v12.0.0, we see the introduction of a new implementation of ES Modules in Node.js. 🎉
Note: ES Modules features are still Experimental and as such should not be used in production code until they are finalized.
At release, this new implementation has replaced the previous implementation behind the
--experimental-modules flag. This is intended to help get the new implementation out there and tested so the project can get feedback. If all goes well (🤞), this can ship unflagged once Node.js v12 goes LTS in October!
Up front, I want to say this is going to be a tl;dr. If you're interested in a deeper dive into the new hotness around ESM in Node.js, please check out the blog post by the Modules Team on Medium.
Many of the previous implementation's features carried over. This includes ES2015
import statements, various kinds of
export support on all core modules, WIP imports for CommonJS, very WIP loader API, and explicit ESM parsing if the
.mjs file extension is present.
These features are 100% new with the enhancements the Modules Team has been working on, and are available behind the
--experimental-modules flag in Node.js v12.0.0.
"type": "module" in
.js files in your project as ES Modules.
.cjs file extension, which will tell Node.js to parse them as CommonJS explicitly
--input-type flag for cases like
--eval and STDIN
These features are currently being worked on by the Modules team and are either implemented but are likely going to change or are being worked on but did not ship in Node.js v12.0.0.
--loader API has shipped, but it's going to be improved upon and, as such, change.
require in ES Modules code.
If you're interested in seeing what ESM in Node.js looks like, you can check out two repos I pushed out yesterday:
I'm planning to keep these repos (and the version of simple-esm published to npm) both up-to-date as the ESM implementation changes both for my own understanding and as a community resource to have a minimum viable example of ESM in Node.js.
This release included a major V8 upgrade, jumping forward several releases to the most recent version of V8 at time of release. This upgrade includes a plethora of really fantastic enhancements. I'm personally most interested in Zero-cost Async Stack Traces, but there are a plethora of additional enhancements that are better outlined by Mathias Bynens from the V8 team:
Next up, we have official TLS 1.3 support. This is an incredible improvement to previous TLS versions, and I'm super excited that it's now supported in a release line that'll be going LTS! Thankfully, this is a backward compatible change thanks to the underlying implementation in OpenSSL 1.1.1. Additionally, it's mentioned in the PR that it should be backported to other LTS release lines.
If you're curious about the awesome parts of TLS 1.3, I recommend this blog post from the IETF.
This is the first LTS release line that will include the currently-experimental work on Worker Threads. This release has removed the need to run Worker Threads with a flag, hopefully lowering the barrier to more widespread usage of the tool for parallelizing work in Node.js.
If you're interested in trying out Worker Threads today, there are a few resources you can use to get started:
In this release, we also see built-in heap snapshotting adapted from the heapdump module on npm. This is exposed via
v8.getHeapSnapshot() and returns a readable stream.
main entries in
package.json will now throw an error (nodejs/node#26823)
node --debug is now EOL – use
node --inspect instead (nodejs/node#25828)
Hopefully this overview of the new release is helpful to you! If you've got any questions about the new features that've shipped, when you can start expecting to use ESM in Node.js, or anything else about Node.js v12 I'm happy to be a resource for you to hopefully find the answers you're looking for!