Skip to main content

Introduction

The nuqs/server package provides server-side utilities for parsing and working with URL search parameters in server components, loaders, and API routes. Unlike the main nuqs package which is designed for client-side React components, nuqs/server has no client-side dependencies and can be safely imported in server contexts.

Import from nuqs/server

When working in server-side contexts, always import from nuqs/server to avoid bundling client-side code:
Do not import from nuqs in server components or server-side code, as it includes the "use client" directive and client-side dependencies.

Available Server Exports

The nuqs/server package exports:
  • createSearchParamsCache - For accessing search params in nested server components
  • createLoader - For parsing search params in loaders, API routes, and one-off operations
  • createSerializer - For generating URLs with search params (e.g., for <Link> components)
  • All parsers - parseAsString, parseAsInteger, parseAsFloat, parseAsBoolean, parseAsTimestamp, parseAsIsoDateTime, parseAsArrayOf, parseAsJson, parseAsStringEnum, parseAsStringLiteral, parseAsNumberLiteral, etc.
  • Type utilities - inferParserType, UrlKeys, SearchParams, Options, etc.
  • Rate limiting utilities - debounce, throttle, defaultRateLimit

Server-Side Use Cases

Next.js App Router

In Next.js app router pages and server components:

Remix Loaders

React Router Loaders

API Routes

Type Safety

All server-side utilities maintain full type safety. TypeScript will correctly infer the types of parsed values based on the parsers you provide:

Sharing Parser Configurations

You can share parser configurations between client and server code:

Next Steps

Loaders

Learn about createLoader for one-off parsing

Cache

Use createSearchParamsCache for server components

Serializer

Generate URLs with createSerializer