Node.js latest features
There are some relevant new features in the latest versions of Node (18 and 19); let’s see what is new in those versions.
Experimental Fetch API
Node.js 18 (also in version 19) includes an experimental global Fetch API that is now available by default. The API’s implementation is inspired by node-fetch, which is originally based on undici-fetch and comes from undici. The API’s developers aim to make it as close to the specification as possible, but some features require a browser environment and are thus omitted.
Here is an example that hits the Pokémon API:
const getPokemons = async () => {
const response = await fetch('https://pokeapi.co/api/v2/pokemon')
if (response.ok) {
const pokemons = await response.json()
console.log(pokemons)
} else {
console.error(`${response.status} ${response.statusText}`)
}
}
getPokemons()
This addition to Node.js 18 (also included in version 19) makes...