
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@fastify/env
Advanced tools
Fastify plugin to check environment variables
npm i @fastify/env
const fastify = require('fastify')()
const fastifyEnv = require('@fastify/env')
const schema = {
type: 'object',
required: [ 'PORT' ],
properties: {
PORT: {
type: 'string',
default: 3000
}
}
}
const options = {
confKey: 'config', // optional, default: 'config'
schema: schema,
data: data // optional, default: process.env
}
fastify
.register(fastifyEnv, options)
.ready((err) => {
if (err) console.error(err)
console.log(fastify.config) // or fastify[options.confKey]
// output: { PORT: 3000 }
})
This module is a wrapper around env-schema.
To read an .env file you must set dotenv in the options:
const options = {
dotenv: true // will read .env in root folder
}
// or, pass config options avalible on dotenv module
const options = {
dotenv: {
path: `${__dirname}/.env`,
debug: true
}
}
The @fastify/env plugin loads asynchronously. If you wish to use its values in a different plugin before the boot sequence, you need to make sure that:
@fastify/env is registered first.await fastify.register(fastifyEnv)
// fastify.config can be used in here
OR
fastify.register(fastifyEnv)
await fastify
// fastify.config can be used in here
NB Support for additional properties in the schema is disabled for this plugin, with the additionalProperties flag set to false internally.
In order to have typing for the fastify instance, you should follow the example below:
declare module 'fastify' {
interface FastifyInstance {
config: { // this should be same as the confKey in options
// specify your typing here
};
}
}
Kindly sponsored by Mia Platform
FAQs
Fastify plugin to check environment variables
The npm package @fastify/env receives a total of 110,668 weekly downloads. As such, @fastify/env popularity was classified as popular.
We found that @fastify/env demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 18 open source maintainers 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.