NodeJS v10.0.0 release, code-named Dubnium, recently came out. Every April Node comes out with a new even-numbered LTS(Long-term support version). What is an LTS version? It means that this version will be supported and maintained by NodeJS for at least 18 months. Thus, it is the kind of version that you should use for production.

The new version comes out with a few cool features. Let us check them out.

  1. Stable N-API
  2. Adoption of Error Codes
  3. Performance improvements
  4. File System promises
  5. Performance tracking
  6. SSL upgrade
  7. New methods
  8. Deprecation
  9. Expected future changes

Stable N-API

NodeJS v8.0.0 had introduced N-API as an experimental feature. The latest v10 release has now moved it to a stable version.

For those of you who do not know about N-API, it is an API for building native V8/NAN APIs.It provides an ABI(Application Binary Interface) stable abstraction layer for native add-ons. As a result, V8/NAN APIs can stay insulated from the changes to the underlying JavaScript engine.

Thus, it allowed modules compiled in one version of NodeJS to run on later versions without the need to recompile them.

For more details on N-API, check out the documentation here.

Adoption of Error Codes

NodeJS v10 will now throw errors with error codes. This will allow easy, reliable and repeatable comparison of errors.

Earlier, the exact string had to be compared with the errors thrown. The error message could typo or a short description. In that case, developers had to wait till the next version came out.

try {
  // Some code
} catch (error) {
  if (error.message === 'Some error message') {
    // Handle certain error 
  }
}

Owning to the new release, error codes are now available for such comparisons. So you now have a dependable way to handle specific errors.

try {
  // Some code
} catch (error) {
  if (err.code === 'SOME_ERROR_CODE') {
    // Handle certain error  
  }
}

You can check out the details of different error here.

Performance improvements

NodeJS utilizes V8 JavaScript engine. The recent version, v10.0.0 is shipped with the latest v6.6 of V8. This means features of V8 like performance improvements in promise, arrays as well as async generators and iterator are now available to NodeJS.

According to the V8 project team, the greatest improvements were in holey double arrays. The throughput performance of Array#reduce was improved 10 times. The V8 project team generated the following graph comparing the improvement in performance for arrays.

You can read more about the improvements in V8 v6.6 here.

File System promises

The latest NodeJS version now allows file system(fs) functions to return promises directly using fs/promises API.

When NodeJS v8 came out it had introduced util.promisify. However, those had to wrap functions that provide a callback API. This resulted in an additional step.

For more information on fs/promises, you can visit the documentation here.

Performance tracking

Now developers would be able to better track code performance issues making use of trace events. Performance events will now emit these trace events. The version v10.0.0 also allows a user to enable/disable trace events at runtime.

SSL Upgrade

In the recent v10.0.0 release, OpenSSL has been updated to version 1.1.0h. This would improve security through the improvements in OpenSSL. Moreover, the change will also allow for the use of Chacha20 stream cipher and Poly1305 authenticator.

You can find OpenSSL version 1.1.0 release notes here, for more details.

New methods

The recent release has added few new methods. I have listed the most prominent ones below

  • NodeJS finally added console.table() method in the latest release.
  • Due to the introduction of V8 v6.6, string methods trimStart/trimEnd are now available.
  • The use of V8 v6.6 also means Function.prototype.toString() will now return the exact source code text, including whitespace and comments.

Deprecation

The v10.0.0 deprecated a few methods as well. Listed below are some of the main ones.

  • Passing a single argument to assert.fail() will now trigger deprecation warning.
  • The release deprecated methods crypto.createCipher() and crypto.createDecipher().
  • process.env is now deprecated for non-string values.
  • Use of require() to access internal dependencies of node will now emit runtime dependencies.

Expected future changes

Even though the current release had a lot of improvements, a few important updates still remain. Future v10.x releases may feature these updates. I will mention some of the important ones below.

Stable HTTP2

NodeJS v8.4.0 introduced HTTP/2 as an experimental feature. However, it is expected that this would become stable in future 10.x releases.

For the people who do not have knowledge of HTTP/2, it is the newer better revision of the HTTP protocol. It tries to remove some of the drawbacks of HTTP and the workarounds they cause. Thus, HTTP/2 has some important upgrades including multiplexing and concurrency of requests. Moreover, server can push necessary files even before the client requests them when using HTTP/2.

You can read more about HTTP/2 here.

ECMAScript 6 modules

CommonJS is a module format that comes with NodeJS. However, these are not browser compatible. ES 6 has a standardized module system that is similar to both CommonJS and AMD modules.

Future v10.x versions could try to resolve the remaining incompatibility issues. In particular, the main focus would be to make modules work on a browser as well that and stay compatible with Node.

You can get more information about ES 6 modules here.

npm v6

NodeJS 10.0.0 has currently shipped with npm 5.6.x. However, it is expected that the future NodeJS 10.x releases may be updated with npm v6. The new v6 JavaScript package installer would improve on stability, security and performance improvements compared to previous versions. In fact, the performance enhancement could be as high as 17 times.

If you read more about improvements of npm v6, then you can read them here.