Registry / aws / bragg-env

bragg-env

JSON →
library2.0.0jsnpmunverified

bragg-env is a middleware for the `bragg` serverless framework, designed to automatically extract and expose environment information within the request context (`ctx.env`) for AWS Lambda functions. It leverages the `aws-lambda-env` package to intelligently determine the runtime environment, providing sensible defaults such as `development` when running in `$LATEST` Lambda versions and `production` for other deployed versions. This behavior can be explicitly overridden by setting the `NODE_ENV` environment variable. The package's current stable version is 2.0.0, released approximately four years ago, indicating a mature but inactive state. Both `bragg-env` and its foundational `bragg` framework show no recent development activity or releases, suggesting the package is now abandoned. Its primary utility lies in simplifying environment configuration within the `bragg` ecosystem, abstracting away the specifics of AWS Lambda environment detection, but it lacks modern features and active community support that newer serverless frameworks might offer.

npm install bragg-env
INSTALL
IMPORT
SIG · BRAGG-ENV
B
bragg-env
awsjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

environment
const environment = require('bragg-env');
import environment from 'bragg-env';
bragg-env is a CommonJS module and does not officially support ESM imports. Attempting ESM will likely result in a runtime error.
environment (named)
const { environment } = require('bragg-env');
import { environment } from 'bragg-env';
While `require('bragg-env')` returns the `environment` function directly, destructuring can technically work in CJS but is not the primary export pattern shown in documentation. ESM named import will fail.

Demonstrates how to integrate `bragg-env` middleware into a `bragg` application to expose the detected environment on the context object.

const app = require('bragg')(); const environmentMiddleware = require('bragg-env'); // Optionally set NODE_ENV for testing different environments // process.env.NODE_ENV = 'test'; app.use(environmentMiddleware({ $LATEST: 'development', default: 'production' })); app.use(ctx => { console.log('Detected environment:', ctx.env); // ctx.env will be 'development', 'production', 'test', or another configured value. ctx.res.statusCode = 200; ctx.res.end(`Hello from ${ctx.env} environment!`); }); // To run this, you would typically use a Bragg adapter, e.g., 'bragg-lambda' // For local testing, you might mock a simple server or use a local Bragg runner. // This example primarily demonstrates middleware integration. // Example local execution (conceptual, requires bragg runner setup): // const http = require('http'); // http.createServer(app.callback()).listen(3000, () => { // console.log('Bragg app listening on http://localhost:3000'); // });
Debug
Known issues
gotchaThe `bragg-env` package, along with its core framework `bragg`, appears to be abandoned. The last significant update for both packages was over four years ago, indicating no active development, bug fixes, or security updates. Users should be aware of potential unaddressed vulnerabilities or lack of support for modern Node.js features and practices.
fix
Consider migrating to actively maintained serverless frameworks and their respective environment management solutions for new projects. For existing projects, proceed with caution and thorough security audits.
affects: >=2.0.0
breakingThe package's `engines` field specifies `"node": ">=4"`, which is an extremely old Node.js version. Running `bragg-env` on modern Node.js versions (e.g., 16, 18, 20+) may lead to unexpected behavior, runtime errors, or performance issues due to outdated dependencies or incompatible syntax.
fix
There is no direct fix for this within `bragg-env`. If you must use this package, you might be forced to use older Node.js runtimes, which comes with its own security and maintenance risks. It's strongly recommended to avoid this package in environments requiring modern Node.js versions.
affects: >=2.0.0
gotchaThis package is a CommonJS module and does not support ES Modules (ESM) syntax directly. Attempting to use `import environment from 'bragg-env'` or `import { environment } from 'bragg-env'` in an ESM context will result in a runtime error.
fix
Always use `const environment = require('bragg-env');` for importing this package. If your project is ESM-first, you might need to use dynamic `import()` or review your build configuration to accommodate CommonJS modules, or consider alternatives.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bragg'
The `bragg` framework, which `bragg-env` is middleware for, is not installed or correctly referenced.
fix
Ensure `bragg` is installed: `npm install bragg`. If using a monorepo, verify that `bragg` is resolvable from the `bragg-env` context.
TypeError: app.use is not a function
The `app` object is not a valid `bragg` application instance, or it has not been initialized correctly.
fix
Ensure `app` is initialized as `const app = require('bragg')();` before calling `app.use()`.
ctx.env always returns 'development' or 'production' despite NODE_ENV being set
The `NODE_ENV` environment variable might not be correctly propagated to the Lambda execution environment or the process where `bragg` is running, or the `options` passed to `environment()` might be overriding `NODE_ENV` behavior.
fix
Verify that `process.env.NODE_ENV` is set *before* the `bragg-env` middleware is initialized. If running in AWS Lambda, ensure `NODE_ENV` is configured in the Lambda function's environment variables. Review the `options` object passed to `environment()` to confirm `default` or other keys are not unintentionally preventing `NODE_ENV` from taking precedence.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
braggrequiredCore framework this middleware extends. Implicit peer dependency.
aws-lambda-envrequiredInternal dependency for environment detection logic.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
Resources
bragg-env — npm install bragg-env · libregistry