NodeJS logo.

What's New in NodeJS Version 21.7

NodeJS
JavaScript

Mar 14, 2024 - Sergio Zabala

Goodbye to the dotenv Dependency

The first update brings us native environment variable management without the need for dependencies.

Now with the process.loadEnvFile() function, we can load environment variables directly without having to manually specify the .env file to load.

If we want to load a specific file, we can also pass the path of the file process.loadEnvFile('./.env.prod').

API_KEY=ABXDEDFASDFSGSF
// This would load the default .env file
process.loadEnvFile()

// This would load a specific file
process.loadEnvFile('./.env.dev')

No More Dependencies for Coloring the Console

The second new feature within node is the ability to add colors to your console natively. Previously, libraries like chalk were used. However, from this version of node, we can color it without needing dependencies.

const { styleText } = require('node:util')
const port = 3000

const message = styleText('red', `server started on port ${port}`)

console.log(message)

Conclusion: A Necessary Evolution

These updates simplify the workflow and eliminate the need for additional dependencies.

Although these features are available in the current version of Node, it’s important to mention that they are not considered LTS yet, which means they might not be the most stable option for production environments. However, with the next version 22 on the horizon, expected in April, these features will be ready for wider adoption.