Package Exports
- @arcjet/env
- @arcjet/env/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@arcjet/env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@arcjet/env
Arcjet environment detection.
Currently operates on an environment object with the type:
type Env = {
FLY_APP_NAME?: string;
NODE_ENV?: string;
ARCJET_KEY?: string;
ARCJET_ENV?: string;
ARCJET_LOG_LEVEL?: string;
ARCJET_BASE_URL?: string;
};What is this?
This is a utility that reads configuration for us from process.env and
similar.
It exists so that we can access that configuration throughout our packages.
When should I use this?
You should probably not use this but there are some edge cases where we let users swap more advanced features out and then it may be useful.
Install
This package is ESM only. Install with npm in Node.js:
npm install @arcjet/envExample
import process from "node:process";
import {
apiKey,
baseUrl,
isDevelopment,
logLevel,
platform,
} from "@arcjet/env";
console.log(platform({ FLY_APP_NAME: "foobar" })); // => "fly-io"
console.log(platform({})); // => undefined
console.log(isDevelopment({ NODE_ENV: "production" })); // => false
console.log(isDevelopment({ NODE_ENV: "development" })); // => true
console.log(isDevelopment({ ARCJET_ENV: "production" })); // => false
console.log(isDevelopment({ ARCJET_ENV: "development" })); // => true
console.log(logLevel({ ARCJET_LOG_LEVEL: "debug" })); // => "debug"
console.log(logLevel({ ARCJET_LOG_LEVEL: "info" })); // => "info"
console.log(logLevel({ ARCJET_LOG_LEVEL: "warn" })); // => "warn"
console.log(logLevel({ ARCJET_LOG_LEVEL: "error" })); // => "error"
console.log(logLevel({ ARCJET_LOG_LEVEL: "" })); // => "warn"
console.log(baseUrl(process.env)); // => "https://decide.arcjet.com"
console.log(apiKey({ ARCJET_KEY: "ajkey_abc123" })); // => "ajkey_abc123"
console.log(apiKey({ ARCJET_KEY: "invalid" })); // => undefined