Node.js runtime for Vercel Functions that enables serverless execution of JavaScript and TypeScript code with automatic dependency bundling and TypeScript compilation
npx @tessl/cli install tessl/npm-vercel--node@1.8.0@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.
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.
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 changesimport { 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");
}The @vercel/node runtime is built around several key components:
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;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.
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;
}type NowRequestCookies = { [key: string]: string };
type NowRequestQuery = { [key: string]: string | string[] };
type NowRequestBody = any;This package depends on types from @vercel/build-utils:
Files: Collection of files for build processMeta: Build metadata and environment informationConfig: Build configuration optionsLambda: Serverless function deployment artifact