Create files storing environment variables by using objects.
Use dotenv for loading an .env file in your application.
# Using npm npm install --save obj2env # Using yarn yarn add obj2envvar { item, toArray, toFile } = require("obj2env") console.log(item("PORT", 8080)) // => PORT=8080 console.log(toArray({ PORT: 8080 , NODE_ENV: "production" })) // => [ 'PORT=8080', 'NODE_ENV=production' ] // Will create a file named `.env` in this directory toFile({ PORT: 8080 , NODE_ENV: "production" }, __dirname, err => { err && console.error(err) // The .env file contains: // PORT=8080 // NODE_ENV=production })There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. π
Converts the pair of name and value into a string.
- String
name: The environment variable name. - String
value: The environment variable value.
- String The stringified pair.
Converts an object of environment variables into an array.
- Object
obj: The object containing environment variables to stringify.
- Array An array of stringified pairs.
Create a file named .env in the specified directory.
- Object
obj: The object containing environment variables to stringify. - String
dir: The directory where to create the.envfile (default: the current directory). - Function
cb: The callback function.
- Stream The writable stream.
Have an idea? Found a bug? See how to contribute.
If you are using this library in one of your projects, add it in this list. β¨
obj2env-cli