How to read environment variables in Node.js?

Sometimes, we want to read environment variables in Node.js.

In this article, we’ll look at how to read environment variables in Node.js.

How to read environment variables in Node.js?

To read environment variables in Node.js, we can read them from the process.env property.

For instance, we write

const mode = process.env.NODE_ENV;

to read the NODE_ENV environment variable and assign it to mode.

Conclusion

To read environment variables in Node.js, we can read them from the process.env property.