Runtime Detection
Vestig automatically detects your JavaScript runtime environment, enabling you to write universal code that works everywhere.
Supported Runtimes
| Runtime | Detection | AsyncLocalStorage | Full Support |
|---|---|---|---|
| Node.js | process.versions.node |
✅ Native | ✅ |
| Bun | globalThis.Bun |
✅ Native | ✅ |
| Deno | globalThis.Deno |
✅ via node:async_hooks | ✅ |
| Edge | EdgeRuntime |
⚠️ Limited | ✅ |
| Browser | window / document |
❌ Fallback | ✅ |
| Worker | WorkerGlobalScope |
❌ Fallback | ✅ |
Basic Usage
Checking the Runtime
Runtime Flags
For convenience, Vestig exports boolean flags:
Runtime Capabilities
Not all features are available in all runtimes. Check capabilities:
Capability Matrix
| Capability | Node | Bun | Deno | Edge | Browser | Worker |
|---|---|---|---|---|---|---|
hasAsyncLocalStorage |
✅ | ✅ | ✅ | ⚠️ | ❌ | ❌ |
hasConsole |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
hasProcess |
✅ | ✅ | ✅* | ❌ | ❌ | ❌ |
hasPerformance |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
hasCrypto |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
*Deno 2.0+ has process global for Node.js compatibility
Runtime-Specific Behavior
Logging Output
Vestig adapts its console output based on runtime:
File Transport
The FileTransport is only available in server runtimes:
Environment Variables
Environment variable access differs by runtime:
Writing Universal Code
Pattern: Feature Detection
Pattern: Conditional Imports
Pattern: Runtime-Specific Spans
Edge Runtime Considerations
Edge runtimes (Vercel Edge, Cloudflare Workers) have specific limitations:
Recommended Edge Setup
Deno-Specific Features
Vestig fully supports Deno 2.0+:
Deno Permissions
Vestig requires minimal permissions:
Browser Bundle Size
Vestig is designed to be lightweight in browsers:
Unused features are tree-shaken:
- No FileTransport in browser builds
- No DatadogTransport in browser builds
- Minimal polyfills
API Reference
Constants
| Export | Type | Description |
|---|---|---|
RUNTIME |
Runtime |
Current runtime: 'node', 'bun', 'deno', 'edge', 'browser', 'worker', 'unknown' |
IS_NODE |
boolean |
True if running in Node.js |
IS_BUN |
boolean |
True if running in Bun |
IS_DENO |
boolean |
True if running in Deno |
IS_EDGE |
boolean |
True if running in Edge Runtime |
IS_BROWSER |
boolean |
True if running in browser |
IS_WORKER |
boolean |
True if running in Web Worker |
IS_SERVER |
boolean |
True if Node, Bun, Deno, or Edge |
CAPABILITIES |
RuntimeCapabilities |
Available features in current runtime |
Types
Detection Order
Vestig detects runtimes in this order (first match wins):
- Bun:
'Bun' in globalThis - Deno:
'Deno' in globalThis - Node.js:
process.versions.node - Edge:
'EdgeRuntime' in globalThis - Worker:
typeof WorkerGlobalScope !== 'undefined' - Browser:
typeof window !== 'undefined' - Unknown: fallback
This order ensures correct detection even when runtimes provide compatibility layers (e.g., Deno's Node.js compatibility).