This is a custom setup that helps to set environment variables specified in an .env
-file. This script utilizes dotenv
module and allows to run it without specifying a path to the .env
-file every time. (It's implied that this script is located in the same directory as the .env
-file)
To use this module:
- Install
dotenv
package:
npm i -S dotenv
- Require this module in the beginning of a file and execute a function returned by this module:
require('./config.js')()
const express = require('express')
const app = express()
// etc.
Example of an .env
-file:
# Variables that should not be seen in code
REMOTE_API_KEY=somekey
DATABASE_PASSWORD=thisismypassword