We’ll be talking about these changes in the new Node.js version 18 this article itself. So be sure to read it to the end. So without further ado, let’s get started.
1. Support for ‘fetch’ in Node.js 18
This tweet over here by Matteo Collina confirms that it is very likely that in Node.js version 18, which is the next version of Node and even numbers are LTS versions as well.
So version 18 will introduce the support for a native fetch, finally in Node.js. For the longest time ever Node did not include support for fetch, which is a very very common API on the web, very common API for performing HTTP requests or performing any sort of network request, and Node did not support it by default. If you wanted to perform an HTTP request, either you had to use third-party packages or you would have to construct the request on your own from scratch.
This would be spec complaint that means, fetch should ideally work exactly the way it works inside browser. So there should be no fundamental difference in the way the request is performed in a Node JS environment.
2. Undici Library in Node.js
If you go through this issue, you going to see that Node actually used or mostly ported a library known as Undici. What this library is? Its again, it’s officially built by the Node team itself, but this is like an HTTP 1.1 fully blown client, written it from scratch in Node JS.
Alright, so if you scroll down on this page a bit, you going to see the section which says the fetch request area and it says this is still experimental and it is not yet fully compliant with the fetch standard, so this is important because until and unless this implementation, which pretty much is being used as an official implementation in Node also until and unless this becomes compliant with the fetch standard, Node would not be, you know, just releasing of fetch without an experimental flags are until that happens, Node 18 would probably be not out.
So this is one place which needs a little bit of work. And if you take a look at some unsupported features, you can basically find a lot of stuff. They have documented everything, just that it is not supported yet. You’re going to see that this area, which says specific compliance. All these things, garbage collection and upgrade, this stuff is not I think this garbage collection is not supported.
And of course, if you take a look at the PR, the author who also says that, the tests are not written for fetch area, at least not right now. So that is also something they’re looking forward to.
3. Overview of Node.js Repo
But I think this is a very exciting news in general because Node bringing fetch within its official its core API, means that Node JS developers are finally realising the importance and the need of having a lot of core features and web compliance with the Node runtime itself as well. Now you would have also seen that Node JS is introducing a new way to import modules. It’s using the node protocol or the node namespace whatever you want to say that. So those two-three things combined means that, may be in the future ,maybe in the next few years we would have just slightly that you would have a proper standard like gravy for Node as well, which should ideally replace a lot od commonly used NPM packages which might be unoptimized, which might have breaking changes immediately.
Also, for example, one of the biggest breaking change, which pretty even sum of our bills as as well, was that when this package Node fetch in version 3 shifted to just supporting ESM, just dropping common JS imports and that was like disastrous, if you are not version locking your system, so that’s that sort of thing hopefully does not happen with this sort of implementation.
So yeah, I mean but nonetheless including fetch in Node JS is definitely something which at least I was looking forward for, for a very long time. And finally I could just drop Node fetch as the dependency requirement from the Node 18 onwards. Hopefully this gets shipped by Node 18 but we’ll just see, we’ll have to wait out and see how it goes.
That was it for this article about the change in new Node JS 18 version. If you have any questions, do let me know in the comment box. I would be happy to help you with that.
Thank you for reading this article. Please share it, if you like.
Recommended Articles :
2 thoughts on “What’s New In Node.js Version 18”
Pingback: Apple AirTags can be used to track you! How to be safe? - TechWithAndy
Thank you very much for the provided tools.