The Latest in Node.js Development for 2024

Dung Huynh DucDung Huynh Duc
2 min read

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

Node Fetch built-in in NodeJs 18

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

Read .env file  with NodeJs 20

Testing with node:test

The node:test library in Node.js 20 simplifies the setup and reduces dependencies needed for projects.

node --test

Node runner with NodeJs 20

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 of npm run or of the run 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

Task runner with NodeJs 22

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

experimental-permission with NodeJs 22

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

Import ESM with NodeJs 22

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!

0
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