New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nuxt-envalid

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-envalid

A Nuxt.js module thats validates your env variables and loads them cleaned into your application context

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
increased by4.55%
Maintainers
1
Weekly downloads
 
Created
Source

CI CodeQL License NPM version

nuxt-envalid

A Nuxt.js module thats validates your env variables and loads them cleaned into your application context. Uses envalid under the hood.

Setup

  1. Add nuxt-envalid dependency to your project
yarn add --dev nuxt-envalid # or npm install --save-dev nuxt-envalid
  1. Add nuxt-envalid to the buildModules section of nuxt.config.js

:warning: If you are using a Nuxt version previous than v2.9 you have to install module as a dependency (No --dev or --save-dev flags) and also use modules section in nuxt.config.js instead of buildModules.

export default {
  buildModules: ['nuxt-envalid'],
};

Using inline options

export default {
  buildModules: [
    [
      'nuxt-envalid',
      {
        /* module options */
      },
    ],
  ],
};

Using top level options

export default {
  buildModules: ['nuxt-envalid'],
  envalid: {
    /* module options */
  },
};

Using a function to provide options

export default {
  buildModules: [
    [
      'nuxt-envalid',
      () => ({
        /* module options */
      }),
    ],
  ],
  /* or at top level */
  envalid: () => ({
    /* module options */
  }),
};

Hierarchy

Defining module options inline will overwrite module options defined at top level.

Options

specs

  • Type: { [key: string]: ValidatorSpec }
  • Default: {}

For further information take a look at the official documentation of envalid.

import { bool, str } from 'nuxt-envalid';
export default {
  env: {
    TITLE: 'title',
    IS_PUBLIC: true,
  },
  buildModules: ['nuxt-envalid'],
  envalid: {
    specs: {
      TITLE: str(),
      SUBTITLE: str({ default: 'subtitle' }),
      IS_PUBLIC: bool({ default: false }),
    },
  },
};

options

  • Type: CleanOptions
  • Default: {}

For further information take a look at the official documentation of envalid.

export default {
  buildModules: ['nuxt-envalid'],
  envalid: {
    specs: {
      TITLE: str(),
    },
    options: {
      reporter: ({ errors, env }) => {
        console.log(errors, env);
      },
    },
  },
};

Usage

After creating your .env file in the project root, simply run your usual yarn dev or npm run dev. The variable inside the .env file will be added to the context (context.env) and process (process.env).

Using together with @nuxtjs/dotenv

This module will validate the result of @nuxtjs/dotenv as well and then overwrite the values of the variables defined in the specs. Be sure to include this module AFTER @nuxtjs/dotenv.

# .env file
TITLE='title'
IS_PUBLIC=true
export default {
  buildModules: ['@nuxtjs/dotenv', 'nuxt-envalid'],
  envalid: {
    specs: {
      TITLE: str(),
      SUBTITLE: str({ default: 'subtitle' }),
      IS_PUBLIC: bool({ default: false }),
    },
  },
};

License

MIT License

Keywords

FAQs

Package last updated on 24 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc