{"id":22828709,"url":"https://github.com/busterc/dotenv-assert","last_synced_at":"2025-04-23T16:24:24.956Z","repository":{"id":21953326,"uuid":"25277890","full_name":"busterc/dotenv-assert","owner":"busterc","description":":warning: Requires specified environment settings to exist in node applications","archived":false,"fork":false,"pushed_at":"2015-08-13T19:47:50.000Z","size":121,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T16:24:16.922Z","etag":null,"topics":["conf","config","dotenv","env","environment","environment-variables","environment-vars","environments"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/busterc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-15T23:26:28.000Z","updated_at":"2023-11-30T02:31:58.000Z","dependencies_parsed_at":"2022-07-27T02:47:30.287Z","dependency_job_id":null,"html_url":"https://github.com/busterc/dotenv-assert","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/busterc%2Fdotenv-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/busterc%2Fdotenv-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/busterc%2Fdotenv-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/busterc%2Fdotenv-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/busterc","download_url":"https://codeload.github.com/busterc/dotenv-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250468687,"owners_count":21435528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conf","config","dotenv","env","environment","environment-variables","environment-vars","environments"],"created_at":"2024-12-12T19:11:48.092Z","updated_at":"2025-04-23T16:24:24.925Z","avatar_url":"https://github.com/busterc.png","language":"JavaScript","readme":"# dotenv-assert\n\nRequires specified environment settings to exist in node applications.\n\n## Version 3.0.0\n\n- This module now fully supports sync and async execution\n  - Synchronous execution throws errors (if errors)\n  - Asnychronous execution passes errors to the error-first callback\n\n## Prerequisites\n\n- I highly recommend using **[assert-dotenv](https://github.com/busterc/assert-dotenv)** rather than this module, if you also want to apply environment settings from a `.env` file.\n\n## How does it work\n\nAn exception is thrown if any of these cases are true:\n  - An `assert.env` (or otherwise specified) file is not found\n  - The keys listed in the `assert.env` file are not set on `process.env`\n\nOtherwise, your environment settings are applied and your application executes as expected.\n\n## Why use dotenv-assert\n\n- Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.12factor.net/).\n- Implicit default settings can lead to confusing troubleshooting scenarios and should be avoided entirely.\n- The `assert.env` file only lists what environment settings (keys) are required without providing values like private tokens, passwords, etc. and therefore can and should be checked into version control repositories.\n\n## Installation\n\n```sh\n$ npm install --save dotenv-assert\n```\n\n## Usage\n\n```javascript\n/**\n*  Synchronously load an assert.env file from CWD or\n*  from the nearest parent directory where assert.env is found.\n*/\nrequire('dotenv-assert')();\n\n/**\n*  or, specify a custom file location\n*/\nrequire('dotenv-assert')({\n  filePath: '../configs/assert.config'\n});\n\n/**\n*  or, specify a custom file name (without a path) and it will\n*  be loaded from CWD or the nearest parent directory where\n*  it is found.\n*/\nrequire('dotenv-assert')({\n  filePath: 'env.config'\n});\n\n/**\n*  Asynchronous execution occurs when you provide a callback function\n*/\nrequire('dotenv-assert')(function(error) {\n  if(error) throw error;\n  console.log('Environment Settings Asserted!');\n});\n\n/**\n*  Asynchronous execution works with custom options also\n*/\nrequire('dotenv-assert')({\n    filePath: 'different.env'\n  }, function(error) {\n    if(error) throw error;\n    console.log('Environment Settings Asserted!');\n  });\n\n```\n\n## Simple HTTP Server Example\n\nThis example uses [**dotenv**](https://github.com/motdotla/dotenv) for applying settings, hence the `~/app/.env` file listed below:\n\n- ~/app/.env\n\n  ```\n  IP=127.0.0.1\n  PORT=1337\n  ```\n\n- ~/app/assert.env\n\n  ```\n  IP\n  PORT\n  ```\n\n- ~/app/index.js\n\n  - Synchronous Example\n\n    ```javascript\n    var dotenv = require('dotenv');\n    var dotenvAssert = require('dotenv-assert');\n    var http = require('http');\n\n    dotenv.load();\n    dotenvAssert();\n\n    http.createServer(function (request, response) {\n      response.writeHead(200, {'Content-Type': 'text/plain'});\n      response.end('Hello World\\n');\n    }).listen(process.env.PORT, process.env.IP);\n\n    console.log('Server running at http://' + process.env.IP + ':' + process.env.PORT + '/');\n    ```\n\n  - Asynchronous Example\n\n    ```javascript\n    var dotenv = require('dotenv');\n    var dotenvAssert = require('dotenv-assert');\n\n    dotenv.load();\n\n    dotenvAssert(function(error) {\n      if(error) throw error;\n      var http = require('http');\n\n      http.createServer(function (request, response) {\n        response.writeHead(200, {'Content-Type': 'text/plain'});\n        response.end('Hello World\\n');\n      }).listen(process.env.PORT, process.env.IP);\n\n      console.log('Server running at http://' + process.env.IP + ':' + process.env.PORT + '/');\n    });\n    ```\n\n- _Start the server and see that all is well_\n\n  ```sh\n  $ node ~/app/index.js\n  Server running at http://127.0.0.1:1337/\n  ```\n\n## LICENSE\n\nISC License (ISC)\n\nCopyright \u0026copy; 2014-2015, Buster Collings\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbusterc%2Fdotenv-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbusterc%2Fdotenv-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbusterc%2Fdotenv-assert/lists"}