name: Environment Check
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
envcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Check environment variables
run: npx envcheck-cli --format github --fail-on missingenvcheck:
stage: test
image: node:20-alpine
script:
- npx envcheck-cli --fail-on missing,unused
only:
- merge_requests
- mainversion: 2.1
jobs:
envcheck:
docker:
- image: cimg/node:20.0
steps:
- checkout
- run:
name: Check environment variables
command: npx envcheck-cli --fail-on missing
workflows:
version: 2
test:
jobs:
- envchecklanguage: node_js
node_js:
- 20
script:
- npx envcheck-cli --fail-on missing,unusedpipeline {
agent any
stages {
stage('Environment Check') {
steps {
sh 'npx envcheck-cli --format json --fail-on missing'
}
}
}
}trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '20.x'
- script: npx envcheck-cli --fail-on missing
displayName: 'Check environment variables'Using husky:
{
"husky": {
"hooks": {
"pre-commit": "npx envcheck-cli --fail-on missing"
}
}
}Manual .git/hooks/pre-commit:
#!/bin/sh
echo "Checking environment variables..."
npx envcheck-cli --fail-on missing
if [ $? -ne 0 ]; then
echo "❌ Environment variable check failed"
echo "Please update .env.example or fix the issues"
exit 1
fi
echo "✅ Environment variables OK"#!/bin/sh
npx envcheck-cli --fail-on missing,undocumented.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Check Environment Variables",
"type": "shell",
"command": "npx envcheck-cli",
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": false
}
}
]
}Coming soon: A dedicated VS Code extension for real-time env var validation.
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
# Run envcheck as part of build
RUN npx envcheck-cli --fail-on missing
CMD ["node", "src/index.js"]version: '3.8'
services:
app:
build: .
environment:
- NODE_ENV=production
command: sh -c "npx envcheck-cli && npm start"{
"scripts": {
"pretest": "envcheck",
"prebuild": "envcheck --fail-on missing",
"predeploy": "envcheck --fail-on missing,undocumented",
"env:check": "envcheck",
"env:check:strict": "envcheck --fail-on missing,unused,undocumented"
}
}{
"scripts": {
"preinstall": "npx envcheck-cli"
}
}{
"scripts": {
"env:check": "lerna exec -- npx envcheck-cli"
}
}{
"targets": {
"envcheck": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "npx envcheck-cli --fail-on missing"
}
}
}
}{
"pipeline": {
"envcheck": {
"cache": false,
"outputs": []
}
}
}vercel.json:
{
"buildCommand": "npx envcheck-cli --fail-on missing && npm run build"
}netlify.toml:
[build]
command = "npx envcheck-cli --fail-on missing && npm run build"Procfile:
release: npx envcheck-cli --fail-on missing
web: npm start
{
"build": {
"builder": "NIXPACKS",
"buildCommand": "npx envcheck-cli && npm run build"
}
}#!/bin/bash
OUTPUT=$(npx envcheck-cli --format json)
ISSUES=$(echo $OUTPUT | jq '.summary.total')
if [ "$ISSUES" -gt 0 ]; then
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"⚠️ Environment variable issues found: $ISSUES\"}" \
$SLACK_WEBHOOK_URL
fi#!/bin/bash
OUTPUT=$(npx envcheck-cli --format json)
ISSUES=$(echo $OUTPUT | jq '.summary.total')
if [ "$ISSUES" -gt 0 ]; then
curl -X POST -H 'Content-Type: application/json' \
-d "{\"content\":\"⚠️ $ISSUES environment variable issues detected\"}" \
$DISCORD_WEBHOOK_URL
fiimport { exec } from 'child_process';
import express from 'express';
const app = express();
app.get('/api/envcheck', (req, res) => {
exec('npx envcheck-cli --format json', (error, stdout) => {
if (error) {
return res.status(500).json({ error: error.message });
}
res.json(JSON.parse(stdout));
});
});
app.listen(3000);import { scanDirectory } from 'envcheck-cli/src/scanner.js';
const results = await scanDirectory('./my-project');
console.log(results);