![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
nuxt-envalid
Advanced tools
A Nuxt.js module thats validates your env variables and loads them cleaned into your application context
env
property of the nuxt.config.js
process.env
.env
file, if loaded together with @nuxtjs/dotenvprocess.env
and context.env
)nuxt-envalid
as dev-dependency to your project via yarn
or npm
:yarn add --dev nuxt-envalid # or npm install --save-dev nuxt-envalid
nuxt-envalid
to the buildModules
section of nuxt.config.js
:// nuxt.config.js
export default {
buildModules: ['nuxt-envalid'],
};
: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
.
// nuxt.config.js
export default {
buildModules: [
[
'nuxt-envalid',
{
/* module config */
},
],
],
};
// nuxt.config.js
export default {
buildModules: ['nuxt-envalid'],
envalid: {
/* module config */
},
};
If you need to use a function to provide the module config you are good to go:
// nuxt.config.js
export default {
buildModules: [
[
'nuxt-envalid',
() => ({
/* module config */
}),
],
],
/* or at top level */
envalid: () => ({
/* module config */
}),
};
:warning: Defining module options inline will overwrite module options defined at top level.
Param | Description | Required | Default |
---|---|---|---|
specs | An object that specifies the format of required vars. | No | |
options | An (optional) object, which supports the following key: | No | |
options.reporter | Pass in a function to override the default error handling and console output. | No |
specs
For further information take a look at the official documentation of envalid.
// nuxt.config.js
import { bool, str } from 'nuxt-envalid';
export default {
buildModules: ['nuxt-envalid'],
envalid: {
specs: {
TITLE: str(),
SUBTITLE: str({ default: 'subtitle' }),
IS_PUBLIC: bool({ default: false }),
},
},
};
options
For further information take a look at the official documentation of envalid.
// nuxt.config.js
export default {
buildModules: ['nuxt-envalid'],
envalid: {
options: {
reporter: ({ errors, env }) => {
console.log(errors, env);
},
},
},
};
env
property in Nuxt config// nuxt.config.js
import { bool, host } from 'nuxt-envalid';
export default {
env: {
BACKEND_HOST: 'backend.example.com',
},
buildModules: ['nuxt-envalid'],
envalid: {
specs: {
BACKEND_HOST: host(),
BACKEND_SECURE: bool({ default: true }),
},
},
};
<!-- pages/index.vue -->
<template>
<div>
<h1>{ { post.title } }</h1>
<p>{ { post.description } }</p>
</div>
</template>
<script>
export default {
async asyncData({ env }) {
const response = await fetch(
`${env.BACKEND_SECURE ? 'https' : 'http'}://${env.BACKEND_HOST}/post/1`
);
const post = await response.json();
return { post };
},
};
</script>
This module will validate the result of @nuxtjs/dotenv
.
:warning: Be sure to include this module AFTER @nuxtjs/dotenv
.
# .env
CTF_CDA_ACCESS_TOKEN="super-secret-access-token"
// nuxt.config.js
import { str } from 'nuxt-envalid';
export default {
env: {
CTF_SPACE_ID: 'my-space-id',
},
buildModules: ['@nuxtjs/dotenv', 'nuxt-envalid'],
envalid: {
specs: {
CTF_SPACE_ID: str(),
CTF_CDA_ACCESS_TOKEN: str(),
CTF_ENVIRONMENT: str({ default: 'production' }),
},
},
};
// plugins/contentful.js
import { createClient } from 'contentful';
export default createClient({
space: process.env.CTF_SPACE_ID,
accessToken: process.env.CTF_CDA_ACCESS_TOKEN,
environment: process.env.CTF_ENVIRONMENT,
});
Since 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.
Validation 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.
FAQs
A Nuxt.js module thats validates your env variables and loads them cleaned into your application context
The npm package nuxt-envalid receives a total of 21 weekly downloads. As such, nuxt-envalid popularity was classified as not popular.
We found that nuxt-envalid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.