0
# std-env
1
2
std-env is a runtime-agnostic JavaScript utility library that provides comprehensive environment detection, platform information, CI/CD provider identification, and runtime detection capabilities. It enables applications to adapt their behavior based on the execution context while maintaining compatibility across Node.js, Deno, Bun, and various edge computing platforms.
3
4
## Package Information
5
6
- **Package Name**: std-env
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install std-env`
10
11
## Core Imports
12
13
```typescript
14
import { env, isNode, isDeno, isCI, provider, platform } from "std-env";
15
```
16
17
For CommonJS:
18
19
```javascript
20
const { env, isNode, isDeno, isCI, provider, platform } = require("std-env");
21
```
22
23
## Basic Usage
24
25
```typescript
26
import { env, isNode, isCI, provider, platform } from "std-env";
27
28
// Access environment variables across runtimes
29
console.log(env.NODE_ENV); // Works in Node.js, Deno, Bun, etc.
30
31
// Runtime detection
32
if (isNode) {
33
console.log("Running in Node.js");
34
} else if (isDeno) {
35
console.log("Running in Deno");
36
}
37
38
// CI/CD provider detection
39
if (isCI) {
40
console.log(`Detected CI provider: ${provider}`);
41
}
42
43
// Platform detection
44
console.log(`Running on: ${platform}`);
45
```
46
47
## Architecture
48
49
std-env is built around several key detection systems:
50
51
- **Environment Variable Access**: Cross-platform proxy for accessing environment variables
52
- **Runtime Detection**: Identifies JavaScript runtime (Node.js, Deno, Bun, edge runtimes)
53
- **Platform Detection**: Operating system and environment flags (Windows, macOS, Linux, CI, debug, etc.)
54
- **Provider Detection**: CI/CD and hosting provider identification (50+ supported providers)
55
- **Process Utilities**: Cross-platform process object access
56
57
## Capabilities
58
59
### Environment Variables
60
61
Cross-platform environment variable access that works consistently across Node.js, Deno, Bun, and browser environments.
62
63
```typescript { .api }
64
const env: EnvObject;
65
const nodeENV: string;
66
67
type EnvObject = Record<string, string | undefined>;
68
```
69
70
[Environment Variables](./environment-variables.md)
71
72
### Environment Detection
73
74
Boolean flags for detecting various environment states including CI, debug, test, production, and development modes.
75
76
```typescript { .api }
77
const isCI: boolean;
78
const isDebug: boolean;
79
const isTest: boolean;
80
const isProduction: boolean;
81
const isDevelopment: boolean;
82
const isMinimal: boolean;
83
const hasTTY: boolean;
84
const hasWindow: boolean;
85
const isColorSupported: boolean;
86
```
87
88
[Environment Detection](./environment-detection.md)
89
90
### Platform Detection
91
92
Operating system and platform identification with boolean flags for common platforms.
93
94
```typescript { .api }
95
const platform: string;
96
const isWindows: boolean;
97
const isLinux: boolean;
98
const isMacOS: boolean;
99
const nodeVersion: string | null;
100
const nodeMajorVersion: number | null;
101
```
102
103
[Platform Detection](./platform-detection.md)
104
105
### Runtime Detection
106
107
JavaScript runtime identification following the WinterCG Runtime Keys proposal, with support for Node.js, Deno, Bun, and various edge computing platforms.
108
109
```typescript { .api }
110
const isNode: boolean;
111
const isDeno: boolean;
112
const isBun: boolean;
113
const isFastly: boolean;
114
const isNetlify: boolean;
115
const isEdgeLight: boolean;
116
const isWorkerd: boolean;
117
const runtime: RuntimeName;
118
const runtimeInfo: RuntimeInfo | undefined;
119
120
type RuntimeName = "workerd" | "deno" | "netlify" | "node" | "bun" | "edge-light" | "fastly" | "";
121
interface RuntimeInfo { name: RuntimeName; }
122
```
123
124
[Runtime Detection](./runtime-detection.md)
125
126
### Provider Detection
127
128
CI/CD and hosting provider identification with support for 50+ popular services including GitHub Actions, GitLab CI, Vercel, Netlify, and many others.
129
130
```typescript { .api }
131
const provider: ProviderName;
132
const providerInfo: ProviderInfo;
133
134
type ProviderName = "" | "github_actions" | "gitlab" | "vercel" | "netlify" | /* ...50+ more providers */;
135
interface ProviderInfo {
136
name: ProviderName;
137
ci?: boolean;
138
[meta: string]: any;
139
}
140
```
141
142
[Provider Detection](./provider-detection.md)
143
144
### Process Utilities
145
146
Cross-platform process object access that provides consistent process information across different JavaScript runtimes.
147
148
```typescript { .api }
149
const process: Process;
150
151
interface Process extends Partial<Omit<typeof globalThis.process, "versions">> {
152
env: EnvObject;
153
versions: Record<string, string>;
154
}
155
```
156
157
The `process` object provides a unified interface for accessing process information across Node.js, Deno, Bun, and other JavaScript runtimes.
158
159
## Types
160
161
Core type definitions are included within each capability section above. All types referenced in API signatures are fully defined to ensure complete documentation coverage.