Arcjet environment detection
npm install @arcjet/env@arcjet/env[Arcjet][arcjet] environment detection.
Currently operates on an environment object with the type:
``ts`
type Env = {
ARCJET_BASE_URL?: string;
ARCJET_ENV?: string;
ARCJET_LOG_LEVEL?: string;
FIREBASE_CONFIG?: string;
FLY_APP_NAME?: string;
MODE?: string;
NODE_ENV?: string;
RENDER?: string;
VERCEL?: string;
};
- npm package (@arcjet/env)
- GitHub source code (env/ in arcjet/arcjet-js)
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.
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.
This package is ESM only.
Install with npm in Node.js:
`sh`
npm install @arcjet/env
`ts
import process from "node:process";
import { 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"
``
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
[arcjet]: https://arcjet.com
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0