출처 : https://medium.com/the-node-js-collection/node-js-16-available-now-7f5099a97e70
새로 이직한 회사에서 맡게 된 업무의 일환으로 Node 16에 대해서 조사할 일이 있어 정리하는 포스팅입니다.
Node.js 16 available now
2021년 4월 20일 Node.js 16 버전이 공개됐습니다. 6개월이 지난 같은 해 10월에 LTS (Long-term Support)로 승격, 2023년 9월 11일 지원 종료될 예정이며 코드명 ‘갈륨 (Gallium)’이 붙었습니다. Node.js는 짝수 버전만 LTS에 승격되기 때문에 Node 15를 건너뛴 14 -> 16 으로 업그레이드 됐다고 볼 수 있겠습니다.
참고로 다음 버전인 Node.js 18은 2022년 4월 19일 최초 공개, 같은 해 10월 25일에 LTS로 승격됩니다.
1. V8 자바스크립트 엔진 V9.0 업데이트
Node 15에서 버전8.6이던 V8 엔진이 Node 16에서 버전 9로 업데이트되었습니다. 이에 따라 캡처된 문자열의 시작과 끝 인덱스를 제공하는 ECMAScript RegExp Match Indices
를 지원합니다. 인덱스 배열은 정규식에 /d
플래그가 있는 경우 일치하는 객체의 .indices
프로퍼티를 통해 사용 가능합니다.
This update brings the ECMAScript RegExp Match Indices, which provide the start and end indices of the captured string. The indices array is available via the .indices property on match objects when the regular expression has the /d flag.
1
2
3
4
5
6
7
8
const re = /(a)(b)/d; // Note the /d flag.
const m = re.exec("ab");
console.log(m.indices[0]); // Index 0 is the whole match.
// → [0, 2]
console.log(m.indices[1]); // Index 1 is the 1st capture group.
// → [0, 1]
console.log(m.indices[2]); // Index 2 is the 2nd capture group.
// → [1, 2]
콘솔 창에서 보다 정확하게 확인이 가능합니다.
자세한 내용은 v8 블로그에서 볼 수 있습니다.
2. Timers Promises API 안정화
기존의 setTimeout
과 같은 타이머 API는 프로미스를 반환하지 않아 async\/await이 아닌 주로 콜백함수 형태를 사용했습니다. Timers Promises API를 사용하면 프로미스를 반환하기 때문에 promisify를 사용하지 않아도 async\/await을 사용한 비동기 방식이 가능합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
// Old
function demoOld() {
setTimeout(() => {
console.log("Timer expired.");
}, 5000);
}
// New
import { setTimeout } from "timers/promises";
async function demoNew() {
await setTimeout(5000);
console.log("Timer expired.");
}
3. Node 15 features
Node.js 15에서 공개된 기능들은 당연히 Node.js 16에 포함이 됩니다.
4. Apple silicon M1 지원
Node 16부터 애플 실리콘 arm64 아키텍처 지원을 시작했습니다. intel(darwin-x64
) 및 ARM(darwin-arm64
)아키텍처에 대해 별도의 tarball을 제공할 예정이지만 macOS 설치프로그램(.pkg
)은 ‘fat’ 바이너리로 제공됩니다.
5. Deprecations (지원 중단)
process.binding()
을 비롯한 런타임 지원이 중단되었습니다.