{"id":20650397,"url":"https://github.com/rodrigoespinosa/lookenv","last_synced_at":"2025-04-17T01:43:42.314Z","repository":{"id":48153444,"uuid":"107823672","full_name":"RodrigoEspinosa/lookenv","owner":"RodrigoEspinosa","description":"Set rules for the environment variables in your project. Works great with dotenv","archived":false,"fork":false,"pushed_at":"2018-12-28T16:14:44.000Z","size":164,"stargazers_count":52,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T05:51:16.959Z","etag":null,"topics":["dotenv","javascript","lookenv"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/lookenv","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RodrigoEspinosa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-21T23:37:22.000Z","updated_at":"2023-07-06T10:24:59.000Z","dependencies_parsed_at":"2022-08-26T08:02:04.430Z","dependency_job_id":null,"html_url":"https://github.com/RodrigoEspinosa/lookenv","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoEspinosa%2Flookenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoEspinosa%2Flookenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoEspinosa%2Flookenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoEspinosa%2Flookenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RodrigoEspinosa","download_url":"https://codeload.github.com/RodrigoEspinosa/lookenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249298914,"owners_count":21246728,"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":["dotenv","javascript","lookenv"],"created_at":"2024-11-16T17:19:47.230Z","updated_at":"2025-04-17T01:43:42.296Z","avatar_url":"https://github.com/RodrigoEspinosa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lookenv\n\n\u003cimg alt=\"lookenv\" title=\"lookenv\" width=\"256\" src=\"https://github.com/RodrigoEspinosa/lookenv/blob/82e61a67e8f1d5fee0eb95cbbc0327dac74254f7/lookenv.png\" align=\"right\" /\u003e\n\n\u003e Set rules for the environment variables in your project.\n\n[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Downloads Stats][npm-downloads]][npm-url]\n\n`lookenv` can check if all the variables you need are present before starting your app. It also can set defaults for those variables that are not present. Works fine with `dotenv` or `dotenv-safe`.\n\n## Installation\n\n```sh\nnpm install lookenv --save\n\n# Or with yarn\nyarn add lookenv\n```\n\n## Usage example\n\nCreate a `lookenv.config.js` file, or `.lookenvrc` that exposes a JSON like the following:\n\n```js\nmodule.exports = {\n  MY_ENV_VAR: {\n    required: true\n  },\n  MY_SECOND_ENV_VAR: {\n    default: 'testing'\n  }\n}\n```\n\nThen, add `lookenv` to the `package.json` start script, before the app starts but after dotenv (if you are using it!).\n\n```json\n{\n  \"start\": \"lookenv -- node index.js\"\n}\n```\n\nYou can also specify a path to the config file, or the directory where the config file by passing `--path` or `-p`.\n\n```json\n{\n  \"start\": \"lookenv --path=lookenv.config.js -- node index.js\"\n}\n```\n\n### With `dotenv`\n\nYou can pass a `--dotenv` (or `-d` for short) to the cli to load `dotenv` before\nvalidating the env vars.\n\n```json\n  \"start\": \"lookenv --dotenv -- node index.js\"\n```\n\n_You can optionally pass the location of your `.env` in the `--dotenv` option,\nlike `lookenv --dotenv=/path/to/custom/env -- node index.js`._\n\n\u003c!--\n  #### With `dotenv`\n\n  If you have a file just for the `lookenv.validate` (as the example above), then you would need to set the `require('dotenv').config()` on the first line of both files, the `lookenv-validate.js` **and** the entry point of your app.\n\n  ```js\n  require('dotenv').config()\n\n  lookenv.validate()\n    .then(() =\u003e {\n      process.exit(0)\n    })\n    .catch(error =\u003e {\n      console.error(error)\n\n      process.exit(1)\n    })\n  ```\n\n  #### With `dotenv-safe`\n\n  `dotenv-safe` will take care of the required ENV VARS from the `.env.example.js`, you can setup extra required variables or use `lookenv` just for setting defaults. That's actually encourage as a transition.\n\n  The code would look the same as \"With `dotenv`\" but replacing `dotenv` with `dotenv-safe`.\n--\u003e\n\n### With [`Joi`](https://github.com/hapijs/joi)\n\n_Joi, the object schema description language and validator for JavaScript objects._\n\nLookenv recognizes and supports Joi schemas from the config files. In order to do so, please remember to install (`npm install --save joi`) in your project. And then, export the Joi schema in your `lookenv.config.js` file.\n\n```js\nconst Joi = require('joi');\n\nmodule.exports = Joi.object().keys({\n  A_NUMBER: Joi.number().required(),\n  A_STRING: Joi.string().required(),\n  AN_OBJECT: Joi.string().required(),\n\n  A_PORT: Joi.number()\n    .positive()\n    .default(3000),\n\n  A_NUMBER_WITH_DEFAULTS: Joi.number().default(7),\n  A_STRING_WITH_DEFAULTS: Joi.string().default('seven')\n})\n```\n\nThis means that you can use the entire [Joi Schema API](https://github.com/hapijs/joi/blob/v13.0.2/API.md) to validate your env vars.\n\n### Using it just for setting defaults\n\nEverything would be the same, but you can use the simplified `lookenv.config.js` (or `.lookenvrc`) json that matches every key with a default.\n\n```json\n{\n  \"MY_ENV_VAR\": \"my-default\",\n  \"MY_2ND_ENV_VAR\": \"other-default\"\n}\n```\n\nYou can also combine them!\n\n```json\n{\n  \"MY_ENV_VAR\": \"my-default\",\n  \"MY_2ND_ENV_VAR\": {\n    \"required\": true\n  }\n}\n```\n\n## API\n\n**`lookenv.config({ path })`**\nThis method will only call the config and return the set of rules, it won't do any validation.\n\n**`lookenv.validate({ path, context })`**\nThis method will get the config for the `lookenv.config.js` (or `.lookenvrc`) from the current working directory (using `process.cwd()`), unless you specify a `path` to the config file in question.\n\nAfter that, it will validate the `context` (that is `process.env` as default) and apply all the defaults.\n\nIf there is a required variable that isn't present, it will throw an error specifying the missing variables.\n\n\n## Programmatic use\n\n```js\nconst lookenv = require('lookenv')\n\nlookenv.validate()\n  .then(() =\u003e {\n    // ... your app goes here, basically...\n  })\n  .catch(error =\u003e {\n    console.error(error)\n    process.exit(1)\n  })\n```\n\n_Remember that `lookenv.validate` is async._\n\n## Development setup\n\nThis project use `ava` to run tests. Just [fork it](https://github.com/RodrigoEspinosa/lookenv/fork).\n\n```sh\nnpm test\n\n# Or with yarn\nyarn test\n```\n\n## Release History\n\nSee [`CHANGELOG.md`](https://github.com/RodrigoEspinosa/lookenv/blob/master/CHANGELOG.md)\n\n## Meta\n\nREC – [@reciam](https://twitter.com/reciam) – yo@rec.cool\n\nDistributed under the MIT license. See ``LICENSE`` for more information.\n\n[https://github.com/RodrigoEspinosa/lookenv](https://github.com/RodrigoEspinosa/lookenv)\n\n**Credits of the logo goes to [@guillecura](http://guillecura.co/).**\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/RodrigoEspinosa/lookenv/fork\u003e)\n2. Create your feature branch (`git checkout -b feature/foo-bar`)\n3. Commit your changes (`git commit -am 'Add some foo and bar'`)\n4. Push to the branch (`git push origin feature/foo-bar`)\n5. Create a new Pull Request\n\n\u003c!-- Markdown link \u0026 img dfn's --\u003e\n[npm-image]: https://img.shields.io/npm/v/lookenv.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/lookenv\n[npm-downloads]: https://img.shields.io/npm/dm/lookenv.svg?style=flat-square\n[travis-image]: https://img.shields.io/travis/RodrigoEspinosa/lookenv/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/RodrigoEspinosa/lookenv\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigoespinosa%2Flookenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigoespinosa%2Flookenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigoespinosa%2Flookenv/lists"}