Node.js Backend SDK
API reference for the Layercode Node.js Backend SDK.
Introduction
The Layercode Node.js Backend SDK provides a simple way to handle the Layercode webhook in your backend. In particular, it makes it easy to return SSE events in the Layercode webhook response format. It supports all popular JavaScript runtime environments, including Node.js, Bun, and Cloudflare Workers.
See our Backend Guides for more information about how to use the SDK in your project.
Installation
Usage
Reference
streamResponse
The streamResponse
function is the main entry point for the SDK. It takes the request body (from the Layercode webhook request) and a handler function as arguments. The handler function receives a stream
object that can be used to send SSE events to the client.
Parameters
requestBody
: The request body from the client. See Webhook Request Payload.handler
: An async function that receives astream
object.
Stream Methods
stream.tts(content: string)
: Sends a text to be spoken to the user (tts stands for text-to-speech).stream.data(content: any)
: Sends any arbitrary data to the frontend client. Use this for updating your frontend UI.stream.end()
: Closes the stream. Must be called at the end of your response.
Examples
Here are some examples of how to use the Node SDK. See the corresponding guides for more details: