How to store Node.js deployment settings/configuration files?

Sometimes, we want to store Node.js deployment settings/configuration files.

In this article, we’ll look at how to store Node.js deployment settings/configuration files.

How to store Node.js deployment settings/configuration files?

To store Node.js deployment settings/configuration files, we can use the dotenv package.

To install it, we run

npm i dotenv

Then we write

const dotenv = require('dotenv');
dotenv.load();

to require the dotenv package.

And then we call dotenv.load to load our config file.

Then in our .env file, we can put some config entries like

S3_BUCKET=bucket
SECRET_KEY=secret
OTHER_SECRET_STUFF=secret

And the data from the .env file will be put in the process.env object with the keys in .env as the property names.

Conclusion

To store Node.js deployment settings/configuration files, we can use the dotenv package.