What's new in the Node.js v18.x release?
Tags: node, javascript, fetch, typescript
Published: 2022-04-21 09:58:24

Node.js 18 is released recently, There are some interesting features added in Node.js 18. 

Node.js 18 will be the 'Current' release for the next 6 months and then promoted to Long-term Support (LTS) in October 2022. Once promoted to long-term support the release will be designated the codename 'Hydrogen'. Node.js 18 will be supported until April 2025.

##### Release Note: [here](https://nodejs.org/en/blog/announcements/v18-release-announce/#v8-10-1)

### Features of Node.js 18.x:

#### fetch (experimental)

It's been a long-waited feature of Node.js 18. It is a new fetch API that is based on the WHATWG Fetch standard.
fetch is already supported by almost all modern browsers.

```javascript
const get = async (url) => {
  const res = await fetch(url);
  if (res.ok) {
    const data = await res.json();
    console.log(data);
  }
};
```

###### It's possible to disable the API by supplying the --no-experimental-fetch command-line flag.

---

#### Web Streams API (experimental)

Node.js 18 introduces the Web Streams API. It'll be globally available now.

- ReadableStream
- ReadableStreamDefaultReader
- ReadableStreamBYOBReader
- ReadableStreamBYOBRequest
- ReadableByteStreamController
- ReadableStreamDefaultController
- TransformStream
- TransformStreamDefaultController
- WritableStream
- WritableStreamDefaultWriter
- WritableStreamDefaultController
- ByteLengthQueuingStrategy
- CountQueuingStrategy
- TextEncoderStream
- TextDecoderStream
- CompressionStream
- DecompressionStream.

---

#### Test runner module (experimental)

This is a new test runner module that does not completely replace other test runners like jest or mocha. but does offer a quick and easy way to run a test suite without any additional dependencies.

```javascript
import test from "node:test";
test("Number:Test", async (t) => {
  await t.test("Check numbers are equal", () => {
    assert.strictEqual(1, 1);
  });
});
```

---

#### V8 engine update

The V8 engine is updated to version 10.1, which is part of Chromium 101.
https://nodejs.org/en/blog/announcements/v18-release-announce/#v8-10-1

---

##### Must Read If you haven't

###### [Javascript console Methods: A Cheat Sheet for Developers](https://dev.to/devsmitra/javascript-console-methods-a-cheat-sheet-for-developers-44mc)

###### [How to cancel Javascript API request with AbortController](https://dev.to/devsmitra/how-to-cancel-javascript-api-request-with-abortcontroller-36cm)

###### [How to solve Express.js REST API routing problem with typescript decorators?](https://dev.to/devsmitra/how-to-solve-rest-api-routing-problem-with-decorators-5b3n)

###### [Javascript short reusable functions trick and tips](https://dev.to/devsmitra/javascript-short-reusable-functions-everyone-will-always-need-22oc)

---

###### More content at [Dev.to](https://dev.to/devsmitra "Rahul Sharma(DevsMitra)").

###### Catch me on [YouTube](https://www.youtube.com/channel/UCQkvNcHN5vg3jEoeOb9Tdrw?sub_confirmation=1 "Rahul Sharma(DevsMitra)"), [Github](https://github.com/devsmitra "Rahul Sharma(DevsMitra)"), [Twitter](https://twitter.com/devsmitraa "Rahul Sharma(DevsMitra)"), [LinkedIn](https://www.linkedin.com/in/rahul-sharma-18b8b374 "Rahul Sharma(DevsMitra)"), [Medium](https://devsmitra.medium.com "Rahul Sharma(DevsMitra)"), [Stackblitz](https://stackblitz.com/@devsmitra "Rahul Sharma(DevsMitra)"), [Hashnode](https://devsmitra.hashnode.dev "Rahul Sharma(DevsMitra)"), [HackerNoon] (https://hackernoon.com/u/devsmitra "Rahul Sharma(DevsMitra)"), and [Blogspot](https://devsmitra.blogspot.com "Rahul Sharma(DevsMitra)").