@lastshotlabs/slingshot-runtime-node
npm install @lastshotlabs/slingshot-runtime-node
Functions
Section titled “Functions”configureRuntimeNodeLogger
Section titled “configureRuntimeNodeLogger”Replace the runtime’s structured logger. Pass null to reset to the default
console-backed logger. Returns the previous logger so tests can save and
restore the state.
function configureRuntimeNodeLogger(logger: RuntimeNodeLogger | null): RuntimeNodeLoggerSource: packages/runtime-node/src/index.ts
configureRuntimeNodeStructuredLogger
Section titled “configureRuntimeNodeStructuredLogger”Replace the structured Logger. Pass null to reset to the default JSON
console logger. Returns the previous logger so tests can save and restore
state.
function configureRuntimeNodeStructuredLogger(logger: Logger | null): LoggerSource: packages/runtime-node/src/index.ts
installProcessSafetyNet
Section titled “installProcessSafetyNet”Install once-per-process handlers for unhandledRejection and
uncaughtException. Both are forwarded to the structured logger, then a
process exit is scheduled so production does not continue in an undefined
state.
Idempotent — safe to call across multiple nodeRuntime() invocations in the
same process.
function installProcessSafetyNet(): voidSource: packages/runtime-node/src/index.ts
nodeRuntime
Section titled “nodeRuntime”Creates a SlingshotRuntime implementation powered by the Node.js runtime.
Provides the following capabilities using Node.js built-ins and peer dependencies:
- password —
argon2(peer dep:argon2) for hashing and verification - sqlite —
better-sqlite3(peer dep:better-sqlite3) with WAL mode enabled - server —
@hono/node-server(peer dep:@hono/node-server) wrapping Node’shttp.Server - fs —
node:fs/promisesfor async file I/O with ENOENT-safereadFile - glob —
fast-glob(peer dep:fast-glob) for file pattern scanning
Runtime contract enforcement. Unlike earlier versions, this runtime fully
implements the RuntimeServerOptions and RuntimeWebSocketHandler contract:
maxRequestBodySize (413 enforcement), idleTimeout (server-side
heartbeat), perMessageDeflate (compression), and publishToSelf (publish
fan-out) all behave as documented.
Graceful shutdown. instance.stop({ timeoutMs }) drains in-flight
connections for up to timeoutMs before force-closing leftover sockets. The
runtime does not register SIGTERM or SIGINT handlers — process
lifecycle belongs to the calling app. In production, register handlers:
const server = await runtime.server.listen({ ...opts });const drain = async () => {try { await server.stop({ timeoutMs: 25_000 }); } finally { process.exit(0); }};process.once('SIGTERM', drain);process.once('SIGINT', drain);Optionally call installProcessSafetyNet() to forward unhandled rejections
and uncaught exceptions to the structured logger.
Structured logging. Operational events (websocket handler errors,
upgrade timeouts, body-size rejections, drain timeouts, fetch handler
exceptions) are emitted via configureRuntimeNodeLogger. The default
logger writes to console.warn / console.error; production deployments
should swap in a logger that forwards to pino/bunyan/OpenTelemetry.
function nodeRuntime(options?: NodeRuntimeOptions): NodeSlingshotRuntimeSource: packages/runtime-node/src/index.ts
runtimeNodeInternals
Section titled “runtimeNodeInternals”Expose low-level Node runtime helpers for unit-test access.
Source: packages/runtime-node/src/index.ts
Classes
Section titled “Classes”NodeContentLengthError
Section titled “NodeContentLengthError”Raised when an incoming request has an invalid Content-Length header.
Source: packages/runtime-node/src/errors.ts
NodeRequestBodyTooLargeError
Section titled “NodeRequestBodyTooLargeError”Raised when a Node runtime request body exceeds the configured maximum size.
Source: packages/runtime-node/src/errors.ts
NodeRuntimeError
Section titled “NodeRuntimeError”Errors thrown by the Node runtime implementation.
Source: packages/runtime-node/src/errors.ts
NodeServerError
Section titled “NodeServerError”Raised when the Node runtime HTTP server cannot start or serve requests safely.
Source: packages/runtime-node/src/errors.ts
NodeShutdownError
Section titled “NodeShutdownError”Raised when the Node runtime cannot complete server shutdown cleanly.
Source: packages/runtime-node/src/errors.ts
NodeWebSocketError
Section titled “NodeWebSocketError”Raised when Node runtime WebSocket setup or delivery fails.
Source: packages/runtime-node/src/errors.ts
Interfaces
Section titled “Interfaces”NodeRuntimeOptions
Section titled “NodeRuntimeOptions”Per-runtime knobs for the Node.js runtime. None are required — defaults
match the documented behaviour. Pass via nodeRuntime(options).
Source: packages/runtime-node/src/index.ts
NodeRuntimeServerFactory
Section titled “NodeRuntimeServerFactory”The server factory returned by the Node runtime — listen() always resolves
asynchronously to a NodeRuntimeServerInstance.
Source: packages/runtime-node/src/index.ts
NodeRuntimeServerInstance
Section titled “NodeRuntimeServerInstance”The server instance returned by the Node runtime’s server.listen().
Narrows the core RuntimeServerInstance contract to what the Node
implementation actually provides:
stop()always returns a promise and additionally accepts the richer object formstop({ timeoutMs, closeActiveConnections })for bounded graceful drains.upgrade()/publish()are always available (backed byws).
Source: packages/runtime-node/src/index.ts
NodeSlingshotRuntime
Section titled “NodeSlingshotRuntime”The runtime returned by nodeRuntime.
Narrows the core SlingshotRuntime contract to the Node implementation’s
concrete behavior: server.listen() resolves to a
NodeRuntimeServerInstance and glob.scan() (fast-glob) always
resolves to a string[].
Source: packages/runtime-node/src/index.ts
RuntimeNodeLogger
Section titled “RuntimeNodeLogger”Structured logging hook. The runtime emits operational events (websocket
handler errors, upgrade timeouts, body-size rejections, drain timeouts) to
the configured logger. Defaults to defaultLogger which mirrors the
previous console.warn / console.error behaviour.
Pass a custom logger via configureRuntimeNodeLogger to forward into
pino, bunyan, OpenTelemetry logs, etc. — see the README for examples.
Source: packages/runtime-node/src/index.ts