or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-handler-types.mdindex.mdruntime-builder.md
tile.json

tessl/npm-vercel--node

Node.js runtime for Vercel Functions that enables serverless execution of JavaScript and TypeScript code with automatic dependency bundling and TypeScript compilation

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@vercel/node@1.8.x

To install, run

npx @tessl/cli install tessl/npm-vercel--node@1.8.0

index.mddocs/

@vercel/node (Vercel Node.js Runtime)

@vercel/node is a Vercel runtime builder that enables serverless execution of JavaScript and TypeScript code as AWS Lambda functions. It provides automatic dependency bundling, TypeScript compilation, ES module transformation, and development server capabilities for Node.js serverless functions.

Package Information

  • Package Name: @vercel/node
  • Package Type: npm
  • Language: TypeScript
  • Installation: Automatic via Vercel platform
  • Version: 1.8.5

Core Imports

The package exports runtime builder functions and types for Vercel platform integration:

import { build, prepareCache, startDevServer, version, shouldServe } from "@vercel/node";
import { NowRequest, NowResponse, NowApiHandler } from "@vercel/node";

Note: This package is typically used internally by the Vercel platform rather than directly imported by user code.

Basic Usage

Runtime Builder Usage

import { build } from "@vercel/node";

// Build a serverless function
const result = await build({
  files: fileMap,
  entrypoint: "api/handler.js",
  workPath: "/tmp/build",
  config: {},
  meta: {}
});

// result.output contains the Lambda deployment
// result.watch contains files to watch for changes

API Handler Usage

import { NowRequest, NowResponse } from "@vercel/node";

export default function handler(req: NowRequest, res: NowResponse) {
  // Access parsed query parameters
  const { name } = req.query;
  
  // Access parsed cookies
  const token = req.cookies.auth_token;
  
  // Access parsed body (JSON, form data, etc.)
  const data = req.body;
  
  // Send JSON response
  res.status(200).json({ message: `Hello ${name}` });
  
  // Or send plain text
  res.send("Hello World");
  
  // Or redirect
  res.redirect("/login");
}

Architecture

The @vercel/node runtime is built around several key components:

  • Build System: Processes source files, installs dependencies, and creates Lambda deployments
  • TypeScript Compiler: Compiles TypeScript to JavaScript with source map support
  • File Tracer: Analyzes dependencies to create minimal deployment bundles
  • Development Server: Local testing environment with hot reloading
  • Request/Response Abstractions: Enhanced HTTP interfaces for serverless functions
  • Launcher System: Bridges between Vercel platform and user code

Capabilities

Runtime Builder

Core build functionality for creating Lambda deployments from Node.js/TypeScript source code. Handles dependency installation, compilation, and bundling.

function build(options: BuildOptions): Promise<{
  output: Lambda;
  watch: string[];
}>;

function prepareCache(options: PrepareCacheOptions): Promise<Files>;

function startDevServer(options: StartDevServerOptions): Promise<StartDevServerResult>;

const version: number;

function shouldServe(): boolean;

Runtime Builder

API Handler Types

Type definitions for serverless function handlers with enhanced request/response objects that provide automatic parsing and convenience methods.

type NowRequest = IncomingMessage & {
  query: NowRequestQuery;
  cookies: NowRequestCookies;
  body: NowRequestBody;
};

type NowResponse = ServerResponse & {
  send: (body: any) => NowResponse;
  json: (jsonBody: any) => NowResponse;
  status: (statusCode: number) => NowResponse;
  redirect: (statusOrUrl: string | number, url?: string) => NowResponse;
};

type NowApiHandler = (req: NowRequest, res: NowResponse) => void;

Note: All types including NowApiHandler are exported from the main package.

API Handler Types

Types

Build Configuration Types

interface BuildOptions {
  files: Files;
  entrypoint: string;
  workPath: string;
  repoRootPath?: string;
  config?: Config;
  meta?: Meta;
}

interface PrepareCacheOptions {
  workPath: string;
}

interface StartDevServerOptions {
  entrypoint: string;
  workPath: string;
  config?: Config;
  meta?: Meta;
}

interface StartDevServerResult {
  port: number;
  pid: number;
}

Request/Response Types

type NowRequestCookies = { [key: string]: string };
type NowRequestQuery = { [key: string]: string | string[] };
type NowRequestBody = any;

External Dependencies

This package depends on types from @vercel/build-utils:

  • Files: Collection of files for build process
  • Meta: Build metadata and environment information
  • Config: Build configuration options
  • Lambda: Serverless function deployment artifact