npm.io
3.59.0 • Published 15h ago

@platformatic/globals

Licence
Apache-2.0
Version
3.59.0
Deps
3
Size
43 kB
Vulns
0
Weekly
0
Stars
2.0K

@platformatic/globals

Typed accessors for Platformatic runtime APIs.

Applications use @platformatic/globals to read runtime context, use the shared logger, exchange messages, register metrics, customize health checks, and publish metadata while running inside Watt or Platformatic Runtime.

Install

npm install @platformatic/globals

Usage

import { getApplicationId, getLogger, getMessaging } from '@platformatic/globals'

const applicationId = getApplicationId()
const logger = getLogger()
const messaging = getMessaging()

logger.info({ applicationId }, 'Application started')

messaging.handle('ping', () => 'pong')

Runtime APIs are injected when the application runs inside Watt or Platformatic Runtime. Most getters throw when the requested API is not available. Pass { throwOnMissing: false } to return undefined instead:

import { getBasePath } from '@platformatic/globals'

const basePath = getBasePath({ throwOnMissing: false }) ?? ''

Direct access through the legacy globalThis.platformatic object is still supported for compatibility, but deprecated. Use the typed getters and setters instead.

Documentation

See the Runtime APIs reference for the complete API list and examples.

License

Apache 2.0

Keywords