There's more...

If you want to simplify working in development, but also make it easy for others when pushing code to production or other environments, you may want to look into dotenv, an npm package that lets you work with environment variables in text files. Install the package with npm install dotenv --save, and then create a file at the root of your project with the .env extension, which contains the desired variables values:

DB_HOST=127.0.0.1
DB_USER=fkereki
DB_PASS=modernJS!!
DB_SCHEMA=world
SECRET_JWT_KEY=modernJSbook

Then, in your code, you only need to add a single line, and that will load and merge all the definitions in your .env file into process.env. Of course, if you only want to use this feature in development (as it was originally intended by the creator of dotenv) you could previously check the isDev variable, as we saw earlier:

if (isDev) {
dotenv.load();
}

Environment files should never be uploaded to source control, so it makes sense to add a line with **/*.env to your .gitignore file. You can, however, upload a sample file (say, config.env.example), but without the actual values for the environment variables; this will help new developers get the necessary files, but preserve security.

You can learn more about dotenv at https://github.com/motdotla/dotenv.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.37.254