diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index 12c448cf..00000000 --- a/.flowconfig +++ /dev/null @@ -1,23 +0,0 @@ -[ignore] - -[include] - -[libs] - -[lints] -all=warn - -[options] -emoji=true -include_warnings=true - -[strict] -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.105.2 diff --git a/.npmignore b/.npmignore index 83aa0123..40bbf272 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ examples/ flow-typed/ tests/ +types/ .editorconfig .flowconfig .npmignore diff --git a/CHANGELOG.md b/CHANGELOG.md index 25fab38d..30e46f5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,60 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -## [Unreleased](https://github.com/motdotla/dotenv/compare/v11.0.0...master) +## [Unreleased](https://github.com/motdotla/dotenv/compare/v13.0.1...master) - Remove flow ([#584](https://github.com/motdotla/dotenv/pull/584)) - Support inline comments +## [13.0.1](https://github.com/motdotla/dotenv/compare/v13.0.0...v13.0.1) (2022-01-16) + +### Changed + +* Hide comments and newlines from debug output ([#404](https://github.com/motdotla/dotenv/pull/404)) + +## [13.0.0](https://github.com/motdotla/dotenv/compare/v12.0.4...v13.0.0) (2022-01-16) + +### Added + +* Add type file for `config.js` ([#539](https://github.com/motdotla/dotenv/pull/539)) + +## [12.0.4](https://github.com/motdotla/dotenv/compare/v12.0.3...v12.0.4) (2022-01-16) + +### Changed + +* README updates +* Minor order adjustment to package json format + +## [12.0.3](https://github.com/motdotla/dotenv/compare/v12.0.2...v12.0.3) (2022-01-15) + +### Changed + +* Simplified jsdoc for consistency across editors + +## [12.0.2](https://github.com/motdotla/dotenv/compare/v12.0.1...v12.0.2) (2022-01-15) + +### Changed + +* Improve embedded jsdoc type documentation + +## [12.0.1](https://github.com/motdotla/dotenv/compare/v12.0.0...v12.0.1) (2022-01-15) + +### Changed + +* README updates and clarifications + +## [12.0.0](https://github.com/motdotla/dotenv/compare/v11.0.0...v12.0.0) (2022-01-15) + +### Removed + +- _Breaking:_ drop support for Flow static type checker ([#584](https://github.com/motdotla/dotenv/pull/584)) + +### Changed + +- Move types/index.d.ts to lib/main.d.ts ([#585](https://github.com/motdotla/dotenv/pull/585)) +- Typescript cleanup ([#587](https://github.com/motdotla/dotenv/pull/587)) +- Explicit typescript inclusion in package.json ([#566](https://github.com/motdotla/dotenv/pull/566)) + ## [11.0.0](https://github.com/motdotla/dotenv/compare/v10.0.0...v11.0.0) (2022-01-11) ### Changed diff --git a/README.md b/README.md index f39fea83..263f470c 100644 --- a/README.md +++ b/README.md @@ -20,34 +20,56 @@ Dotenv is a zero-dependency module that loads environment variables from a `.env ## Install ```bash -# with npm -npm install dotenv - -# or with Yarn -yarn add dotenv +# install locally (recommended) +npm install dotenv --save ``` +Or installing with yarn? `yarn add dotenv` + ## Usage -As early as possible in your application, require and configure dotenv. +Usage is easy! -```javascript -require('dotenv').config() -``` - -Create a `.env` file in the root directory of your project. Add -environment-specific variables on new lines in the form of `NAME=VALUE`. -For example: +### 1. Create a `.env` file in the **root directory** of your project. ```dosini +# .env file +# +# Add environment-specific variables on new lines in the form of NAME=VALUE +# DB_HOST=localhost DB_USER=root DB_PASS=s1mpl3 ``` +### 2. As early as possible in your application, import and configure dotenv. + +```javascript +// index.js +const dotenv = require('dotenv') +dotenv.config() + +console.log(process.env) // remove this after you've confirmed it working +``` + +.. or using ES6? + +```javascript +// index.mjs (ESM) +import 'dotenv/config' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import +import express from 'express' +``` + +### 3. That's it! 🎉 + `process.env` now has the keys and values you defined in your `.env` file. ```javascript +var dotenv = require('dotenv') +dotenv.config() + +... + const db = require('db') db.connect({ host: process.env.DB_HOST, @@ -56,31 +78,31 @@ db.connect({ }) ``` -### Preload - -You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload dotenv. By doing this, you do not need to require and load dotenv in your application code. This is the preferred approach when using `import` instead of `require`. - -```bash -$ node -r dotenv/config your_script.js -``` +## Examples -The configuration options below are supported as command line arguments in the format `dotenv_config_