The Latest in Node.js Development for 2024
Node Fetch Built-in
With Node.js 18, developers can write cleaner, more efficient code thanks to built-in fetch support, eliminating the need for external libraries.
node index.js
Read .env File Natively
Node.js 20 introduces native support for .env
files, making it easier to manage environment variables. You no longer need to use the dotenv
package.
node --env-file=.env.local index.js
Testing with node:test
The node:test
library in Node.js 20 simplifies the setup and reduces dependencies needed for projects.
node --test
Task runner with node --run
The node --run
command introduced in Node.js 22 provides a built-in mechanism for a task runner, complementing but not replacing existing package managers like npm, yarn, or pnpm.
Intentional limitations
node --run
is not meant to match the behaviors ofnpm run
or of therun
commands of other package managers. The Node.js implementation is intentionally more limited, in order to focus on top performance for the most common use cases.
node --run start
Permission model
Node.js 22 enhances application security with an experimental permission model (--experimental-permission)
, offering controls similar to those seen in Deno.
node --experimental-permission index.js
Import ESM modules from CJS
The ability to import ESM modules from CommonJS scripts under the --experimental-require-module
flag in Node.js 22 simplifies module management and encourages the adoption of ESM.
node --experimental-require-module index.cjs
Conclusion
These features mark just the beginning of whatโs possible with the latest updates in Node.js from versions 18 to 22. To dive deeper and see these features in action, check out the modern-nodejs-2024 repository for hands-on examples.
For a more visual explanation and additional insights, watch my video on YouTube.
Cheers, and happy coding with the new Node.js features!
Subscribe to my newsletter
Read articles from Dung Huynh Duc directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Dung Huynh Duc
Dung Huynh Duc
Hi ๐, I'm Dung Huynh Duc A passionate engineer from Singapore ๐ญ Iโm currently working in AirCarbon ๐จโ๐ป All of my projects are available at https://productsway.com ๐ I regularly write articles on https://productsway.com ๐ซ How to reach me dung@productsway.com ๐น I often publish my video every Sunday on IT Man Channel