How to set an environmental variable in Node.js?

Sometimes, we want to set an environmental variable in Node.js.

In this article, we’ll look at how to set an environmental variable in Node.js.

How to set an environmental variable in Node.js?

To set an environmental variable in Node.js, we can set it as a property of the process.env property.

For instance, we write

process.env['VARIABLE'] = 'value';

or

process.env.VARIABLE = 'value';

to set the VARIABLE environment variable to 'value'.

Conclusion

To set an environmental variable in Node.js, we can set it as a property of the process.env property.