Node 16 now available


By David Fekke
April 21st, 2021

The Node.js foundation just released the first version of Node v16.0.0. The Node.js maintains multiple versions, including the current release along with a long term support (LTS) release. The current v16 release will become the LTS release sometime in October 2021. This is the normal release schedule for Node.

Node.js release schedule

Apple Silicon Support

Apple released a new CPU architecture last November based on ARM64. These are the Macs using the M1 chip from Apple. While Node.js did run on these newer machines, it did so through Apple's Rosetta technology. Rosetta allows x86_64 code to run in emulation on the newer chips. While this is stable, it is not ideal.

Apple M1 chip

You can now download this release through the Node foundation as a .pkg file or through the Node Version Manager. This is the first release with Apple Silicon binaries. The .pkg installer will install a universal binarythat will run either on Apple Silicon processors or on Intel based Macs.

V8 version 9.0

The version of V8, the JavaScript engine for Node.js, has been upgraded to version 9.0. Previously in Node version 15, they were using V8 8.6.

Part of this new version of V8 includes new Regular Expression capabilities for start and end indices of a captured string. This is available when you use the /d flag and access the .indices array property.

Stable Timers Promises API

Stable Timers were previously available in Node v15 under an experimental status. They are now considered a stable feature.

import { setTimeout } from 'timers/promises';

async function doSomething() {
  console.log('doSomething started!');
  await setTimeout(2000);
  console.log('Delayed Timers!');
}
doSomething();

Experimental Web Crypto API

The Web Crypto API is the newer more well defined version of the Crypto library for JavaScript. All of the new Web Crypto methods are available on the subtle interface. Many browsers used an interface called Crypto without having a specific specification. The Web Crypto API adds a standard to the Crypto library.

import { webcrypto } from 'crypto';
const { subtle } = webcrypto;

(async function() {

  const key = await subtle.generateKey({
    name: 'HMAC',
    hash: 'SHA-256',
    length: 256
  }, true, ['sign', 'verify']);

  const digest = await subtle.sign({
    name: 'HMAC'
  }, key, 'I love node.js');

  console.log(digest);
})();

Node-API version 8

The Node API provides an interface for writing Native C++ add-ons as node modules. Version 8 of the Node-API adds native methods for the following methods;

  • napi_add_async_cleanup_hook
  • napi_object_freeze
  • napi_object_seal
  • napi_type_tag_object
  • napi_check_object_type_tag
  • napi_type_tag

AbortController

The AbortController Web API provides a global API that can be used to cancel select promised based APIs. Event listeners should use the { once: true } option ensure that the event listener is removed. Here is an example of the AbortController being used with a event listener;

const abortC = new AbortController();
abortC.signal.addEventListener('abort', () => {
    console.log('Just cancelled')
}, { once: true });
abortC.abort();
console.log(abortC.signal.aborted);

Buffer atob and btoa

These methods for converting data into base64 encoded strings and back where added to support legacy web platform APIs. This is not the preferred way, and should not be used in new code.

The preferred way to convert data into a base64 encoded string is to use the Buffer.from(data, 'base64') method or buf.toString('base64') to convert the buffer into a 'base64' string.

const str = 'Hello JavaScript Developer!';

const strBuf = Buffer.from(str, 'utf8');
console.log(strBuf);
// <Buffer 1d e9 65 a0 96 af 69 27 2b 8a 9b 43 7a f7 a5 a2 97 ab>

const base64Buf = Buffer.from(strBuf, 'base64');
const base64Str = base64Buf.toString('base64');
console.log(base64Str);
// SGVsbG8gSmF2YVNjcmlwdCBEZXZlbG9wZXIh

const bufFromBase64Str = Buffer.from(base64Str, 'base64');

const decodedStr = bufFromBase64Str.toString('utf-8');
console.log(decodedStr);
// Hello JavaScript Developer!
console.log(str === decodedStr);
// true

Other features

  • npm v7.10.0
  • Source Maps v3
  • process.binding() has been deprecated

Conclusion

Node.js upgrades are usually incremental upgrades. As the V8 runtime is upgraded with new features, Node gets these features with the new version of V8. I am looking forward to the LTS release in October.

← Previous Page   Next Page →

Copyright 2024, David Fekke

PHP网站源码萍乡网站推广方案推荐承德企业网站建设多少钱金华百度竞价包年推广哪家好大丰网站关键词优化公司晋城SEO按天扣费公司大连建站推荐海南seo排名报价河源百度竞价包年推广报价果洛网站优化按天收费哪家好中山关键词按天计费报价吕梁网站优化软件报价铜川品牌网站设计哪家好恩施百度关键词包年推广哪家好阳江网络推广推荐荆门企业网站建设推荐济宁网络广告推广推荐福田百姓网标王公司丽江百度标王哪家好肇庆百度seo推荐湘潭外贸网站制作泰安高端网站设计哪家好唐山推广网站哪家好阳泉高端网站设计多少钱菏泽网站优化推广报价黔东南网站制作设计普洱关键词排名包年推广推荐西乡建设网站推荐湛江网站制作设计哪家好天门模板网站建设报价辽阳网站制作推荐歼20紧急升空逼退外机英媒称团队夜以继日筹划王妃复出草木蔓发 春山在望成都发生巨响 当地回应60岁老人炒菠菜未焯水致肾病恶化男子涉嫌走私被判11年却一天牢没坐劳斯莱斯右转逼停直行车网传落水者说“没让你救”系谣言广东通报13岁男孩性侵女童不予立案贵州小伙回应在美国卖三蹦子火了淀粉肠小王子日销售额涨超10倍有个姐真把千机伞做出来了近3万元金手镯仅含足金十克呼北高速交通事故已致14人死亡杨洋拄拐现身医院国产伟哥去年销售近13亿男子给前妻转账 现任妻子起诉要回新基金只募集到26元还是员工自购男孩疑遭霸凌 家长讨说法被踢出群充个话费竟沦为间接洗钱工具新的一天从800个哈欠开始单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#中国投资客涌入日本东京买房两大学生合买彩票中奖一人不认账新加坡主帅:唯一目标击败中国队月嫂回应掌掴婴儿是在赶虫子19岁小伙救下5人后溺亡 多方发声清明节放假3天调休1天张家界的山上“长”满了韩国人?开封王婆为何火了主播靠辱骂母亲走红被批捕封号代拍被何赛飞拿着魔杖追着打阿根廷将发行1万与2万面值的纸币库克现身上海为江西彩礼“减负”的“试婚人”因自嘲式简历走红的教授更新简介殡仪馆花卉高于市场价3倍还重复用网友称在豆瓣酱里吃出老鼠头315晚会后胖东来又人满为患了网友建议重庆地铁不准乘客携带菜筐特朗普谈“凯特王妃P图照”罗斯否认插足凯特王妃婚姻青海通报栏杆断裂小学生跌落住进ICU恒大被罚41.75亿到底怎么缴湖南一县政协主席疑涉刑案被控制茶百道就改标签日期致歉王树国3次鞠躬告别西交大师生张立群任西安交通大学校长杨倩无缘巴黎奥运

PHP网站源码 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化