Node.js runtime for Vercel Functions that enables serverless execution of JavaScript and TypeScript code with automatic dependency bundling and TypeScript compilation
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The runtime builder provides the core functionality for transforming Node.js and TypeScript source code into AWS Lambda-compatible serverless functions for the Vercel platform.
Transforms source code into a deployable Lambda function with all dependencies bundled.
function build(options: BuildOptions): Promise<{
output: Lambda;
watch: string[];
}>;options.files: Collection of source files to buildoptions.entrypoint: Path to the main entry file (e.g., "api/handler.js")options.workPath: Working directory for the build processoptions.repoRootPath: Optional root path of the repositoryoptions.config: Optional build configurationoptions.meta: Optional build metadata and environment infooutput: Lambda deployment artifact ready for executionwatch: Array of file paths to watch for changes in developmentThe build function performs these operations:
vercel-build or now-build)Prepares the node_modules cache for faster subsequent builds.
function prepareCache(options: PrepareCacheOptions): Promise<Files>;options.workPath: Working directory containing node_modulesCollection of cached files from node_modules directory.
import { prepareCache } from "@vercel/node";
const cache = await prepareCache({
workPath: "/tmp/build"
});Starts a local development server for testing serverless functions.
function startDevServer(options: StartDevServerOptions): Promise<StartDevServerResult>;options.entrypoint: Path to the function entry fileoptions.workPath: Working directoryoptions.config: Optional development configurationoptions.meta: Optional metadata including environment variablesport: Port number the dev server is running onpid: Process ID of the dev serverThe development server provides:
import { startDevServer } from "@vercel/node";
const server = await startDevServer({
entrypoint: "api/users.ts",
workPath: process.cwd(),
config: {
helpers: true
},
meta: {
env: {
NODE_ENV: "development"
}
}
});
console.log(`Dev server running on port ${server.port}`);Utility function to determine if files should be served during development.
function shouldServe(): boolean;This function is re-exported from @vercel/build-utils and is used internally by the Vercel platform. It's typically not called directly by user code.
Runtime version number for platform compatibility.
const version: number;Current version is 3, indicating the runtime builder API version.
interface Config {
helpers?: boolean;
includeFiles?: string | string[];
excludeFiles?: string[];
awsLambdaHandler?: string;
}helpers: Enable/disable helper methods on request/response objects (default: true)includeFiles: Glob patterns for additional files to include in bundleexcludeFiles: Patterns for files to exclude from dependency tracingawsLambdaHandler: Custom AWS Lambda handler name for direct Lambda deploymentinterface Meta {
isDev?: boolean;
env?: { [key: string]: string };
buildEnv?: { [key: string]: string };
devCacheDir?: string;
}isDev: Whether building for development (skips dependency installation)env: Environment variables for runtimebuildEnv: Environment variables for build processdevCacheDir: Directory for development cachesBuild errors are thrown as standard JavaScript errors. Common error scenarios:
vercel-build or now-build scripts failtry {
const result = await build({
files: sourceFiles,
entrypoint: "api/handler.ts",
workPath: "/tmp/build"
});
console.log("Build successful!");
} catch (error) {
if (error.message.includes("MODULE_NOT_FOUND")) {
console.error("Missing dependency. Check package.json");
} else {
console.error("Build failed:", error.message);
}
}Install with Tessl CLI
npx tessl i tessl/npm-vercel--node