{"id":20699403,"url":"https://github.com/manuelhenke/nuxt-envalid","last_synced_at":"2025-04-22T22:03:08.383Z","repository":{"id":56740267,"uuid":"524404593","full_name":"manuelhenke/nuxt-envalid","owner":"manuelhenke","description":"Validates your env variables and loads them cleaned into your application context","archived":false,"fork":false,"pushed_at":"2024-10-23T09:13:01.000Z","size":636,"stargazers_count":5,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-24T20:41:24.166Z","etag":null,"topics":["dotenv","envalid","environment-variables","nuxt","nuxt-module","nuxtjs"],"latest_commit_sha":null,"homepage":"https://nuxt-envalid.henkebyte.com","language":"TypeScript","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/manuelhenke.png","metadata":{"funding":{"github":["manuelhenke"]},"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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-13T13:18:19.000Z","updated_at":"2024-09-23T22:19:12.000Z","dependencies_parsed_at":"2024-06-04T03:10:53.758Z","dependency_job_id":"c7ee4184-cc4a-4955-b780-b7b249f6622a","html_url":"https://github.com/manuelhenke/nuxt-envalid","commit_stats":{"total_commits":164,"total_committers":4,"mean_commits":41.0,"dds":0.4695121951219512,"last_synced_commit":"1a366ddff2c2f658f5b953c93ff2d6f639c069f0"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuelhenke%2Fnuxt-envalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuelhenke%2Fnuxt-envalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuelhenke%2Fnuxt-envalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manuelhenke%2Fnuxt-envalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manuelhenke","download_url":"https://codeload.github.com/manuelhenke/nuxt-envalid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250331803,"owners_count":21413100,"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","envalid","environment-variables","nuxt","nuxt-module","nuxtjs"],"created_at":"2024-11-17T00:29:36.437Z","updated_at":"2025-04-22T22:03:08.321Z","avatar_url":"https://github.com/manuelhenke.png","language":"TypeScript","funding_links":["https://github.com/sponsors/manuelhenke"],"categories":[],"sub_categories":[],"readme":"![Logo of nuxt-envalid](/docs/assets/images/banner_1.png)\n\n# nuxt-envalid\n\n[![CI](https://github.com/manuelhenke/nuxt-envalid/actions/workflows/ci.yml/badge.svg)](https://github.com/manuelhenke/nuxt-envalid/actions/workflows/ci.yml)\n[![CodeQL](https://github.com/manuelhenke/nuxt-envalid/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/manuelhenke/nuxt-envalid/actions/workflows/codeql-analysis.yml)\n[![License](https://img.shields.io/github/license/manuelhenke/nuxt-envalid)](./LICENSE)\n[![NPM version](https://img.shields.io/npm/v/nuxt-envalid.svg?style=flat)](https://www.npmjs.com/package/nuxt-envalid)\n\n\u003e Dead simple [Envalid](https://github.com/af/envalid) integration for [Nuxt 2](https://nuxtjs.org).\n\n- ✨ \u0026nbsp;[Release Notes](CHANGELOG.md)\n- 📖 \u0026nbsp;[Documentation](https://nuxt-envalid.henkebyte.com)\n\n## Features\n\n- Define a required schema for your environment variables\n- Validates variables in the `env` property of the `nuxt.config.js`\n- Validates variables in `process.env`\n- Validates variables present in the `.env` file, if loaded together with [@nuxtjs/dotenv](https://github.com/nuxt-community/dotenv-module)\n- Fails the build process if a variable is missing\n- Loads them cleaned and enriched with default values into your application context (`process.env` and `context.env`)\n\n## Getting Started\n\n1. Add `nuxt-envalid` as dev-dependency to your project via `yarn` or `npm`:\n\n```sh\nyarn add --dev nuxt-envalid # or npm install --save-dev nuxt-envalid\n```\n\n2. Add `nuxt-envalid` to the `buildModules` section of `nuxt.config.js`:\n\n```js\n// nuxt.config.js\nexport default {\n  buildModules: ['nuxt-envalid'],\n};\n```\n\n:warning: If you are using a Nuxt version previous than **v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and also use `modules` section in `nuxt.config.js` instead of `buildModules`.\n\n### Inline config\n\n```js\n// nuxt.config.js\nexport default {\n  buildModules: [\n    [\n      'nuxt-envalid',\n      {\n        /* module config */\n      },\n    ],\n  ],\n};\n```\n\n### Top level config\n\n```js\n// nuxt.config.js\nexport default {\n  buildModules: ['nuxt-envalid'],\n  envalid: {\n    /* module config */\n  },\n};\n```\n\n### Config function\n\nIf you need to use a function to provide the module config you are good to go:\n\n```js\n// nuxt.config.js\nexport default {\n  buildModules: [\n    [\n      'nuxt-envalid',\n      () =\u003e ({\n        /* module config */\n      }),\n    ],\n  ],\n  /* or at top level */\n  envalid: () =\u003e ({\n    /* module config */\n  }),\n};\n```\n\n:warning: Defining module options inline will overwrite module options defined at top level.\n\n## Configuration\n\n### Overview\n\n| Param              | Description                                                                   | Required | Default |\n| ------------------ | ----------------------------------------------------------------------------- | -------- | ------- |\n| `specs`            | An object that specifies the format of required vars.                         | No       |         |\n| `options`          | An (optional) object, which supports the following key:                       | No       |         |\n| `options.reporter` | Pass in a function to override the default error handling and console output. | No       |         |\n\n### `specs`\n\nFor further information take a look at the [official documentation of envalid](https://github.com/af/envalid#validator-types).\n\n```js\n// nuxt.config.js\nimport { bool, str } from 'nuxt-envalid';\nexport default {\n  buildModules: ['nuxt-envalid'],\n  envalid: {\n    specs: {\n      TITLE: str(),\n      SUBTITLE: str({ default: 'subtitle' }),\n      IS_PUBLIC: bool({ default: false }),\n    },\n  },\n};\n```\n\n### `options`\n\nFor further information take a look at the [official documentation of envalid](https://github.com/af/envalid#error-reporting).\n\n```js\n// nuxt.config.js\nexport default {\n  buildModules: ['nuxt-envalid'],\n  envalid: {\n    options: {\n      reporter: ({ errors, env }) =\u003e {\n        console.log(errors, env);\n      },\n    },\n  },\n};\n```\n\n## Usage\n\n### Usage with `env` property in Nuxt config\n\n```js\n// nuxt.config.js\nimport { bool, host } from 'nuxt-envalid';\nexport default {\n  env: {\n    BACKEND_HOST: 'backend.example.com',\n  },\n  buildModules: ['nuxt-envalid'],\n  envalid: {\n    specs: {\n      BACKEND_HOST: host(),\n      BACKEND_SECURE: bool({ default: true }),\n    },\n  },\n};\n```\n\n```vue\n\u003c!-- pages/index.vue --\u003e\n\u003ctemplate\u003e\n  \u003cdiv\u003e\n    \u003ch1\u003e{ { post.title } }\u003c/h1\u003e\n    \u003cp\u003e{ { post.description } }\u003c/p\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nexport default {\n  async asyncData({ env }) {\n    const response = await fetch(\n      `${env.BACKEND_SECURE ? 'https' : 'http'}://${env.BACKEND_HOST}/post/1`\n    );\n    const post = await response.json();\n    return { post };\n  },\n};\n\u003c/script\u003e\n```\n\n### Using together with [@nuxtjs/dotenv](https://github.com/nuxt-community/dotenv-module)\n\nThis module will validate the result of `@nuxtjs/dotenv`.\n\n:warning: Be sure to include this module **AFTER** `@nuxtjs/dotenv`.\n\n```sh\n# .env\nCTF_CDA_ACCESS_TOKEN=\"super-secret-access-token\"\n```\n\n```js\n// nuxt.config.js\nimport { str } from 'nuxt-envalid';\nexport default {\n  env: {\n    CTF_SPACE_ID: 'my-space-id',\n  },\n  buildModules: ['@nuxtjs/dotenv', 'nuxt-envalid'],\n  envalid: {\n    specs: {\n      CTF_SPACE_ID: str(),\n      CTF_CDA_ACCESS_TOKEN: str(),\n      CTF_ENVIRONMENT: str({ default: 'production' }),\n    },\n  },\n};\n```\n\n```js\n// plugins/contentful.js\nimport { createClient } from 'contentful';\n\nexport default createClient({\n  space: process.env.CTF_SPACE_ID,\n  accessToken: process.env.CTF_CDA_ACCESS_TOKEN,\n  environment: process.env.CTF_ENVIRONMENT,\n});\n```\n\n### Accessing the data\n\nSince this module is only there to validate the presence of environment variables and to load them sanitized into the already existing `process.env` and `context.env`, the general access of the data doesn't change. Take a look on the official documentation to get a deeper insight [here](https://nuxtjs.org/docs/configuration-glossary/configuration-env/).\n\n### Missing variables\n\nValidation takes places during build time. So if any variable out of the specified configuration is missing in the `env` property of the Nuxt config or in the `.env` file, if `@nuxtjs/dotenv` is used, the build will fail.\n\n## License\n\n[MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanuelhenke%2Fnuxt-envalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanuelhenke%2Fnuxt-envalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanuelhenke%2Fnuxt-envalid/lists"}