@vercel/functions
Utilities for Vercel Serverless and Edge Functions — geolocation, IP detection, and background tasks made easy.
@vercel/functions
Node.jsUtilities for Vercel Serverless and Edge Functions — geolocation, IP detection, and background tasks made easy.
Fit
Bundle (gzip)
4.7 kB
17.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
When building serverless functions on Vercel, common tasks like reading the visitor's IP address, geolocation data, or running background work after a response is sent require digging through raw headers or using workarounds. There's no standard utility for:
- Getting a reliable client IP from behind a proxy/CDN
- Reading geolocation headers (country, city, region) in a clean API
- Keeping a function alive after the response is sent for background processing (e.g. analytics, logging)
What It Does
@vercel/functions provides a set of typed helper functions purpose-built for Vercel's runtime. It handles the edge cases (pun intended) of running in a CDN-proxied environment: IP spoofing protection, geolocation header parsing, and waitUntil for post-response background work.
Installation
npm install @vercel/functionsUsage Example
Get visitor IP address
import { ipAddress } from "@vercel/functions";
export function GET(request: Request) {
const ip = ipAddress(request);
// Returns the real client IP, handles Vercel's proxy headers automatically
return Response.json({ ip });
}Geolocation data
import { geolocation } from "@vercel/functions";
export function GET(request: Request) {
const { city, country, region, latitude, longitude } = geolocation(request);
return Response.json({
message: `Hello from ${city}, ${country}!`,
coords: { latitude, longitude },
});
}waitUntil — run background work after response is sent
import { waitUntil } from "@vercel/functions";
export async function POST(request: Request) {
const body = await request.json();
// Send response immediately — don't make the user wait
const response = Response.json({ status: "ok" });
// This runs AFTER the response is sent, up to the function timeout
waitUntil(
logAnalyticsEvent({ event: "form_submitted", data: body })
);
return response;
}Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.