or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cookie-session.mdglobal-polyfills.mdindex.mdserver-runtime.mdsession-storage.mdstream-utilities.mdupload-handling.md
tile.json

tessl/npm-remix-run--node

Node.js platform abstractions and utilities for Remix applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@remix-run/node@2.17.x

To install, run

npx @tessl/cli install tessl/npm-remix-run--node@2.17.0

index.mddocs/

@remix-run/node

@remix-run/node provides Node.js-specific platform abstractions and utilities for Remix applications. It offers essential Node.js runtime features including file-based session storage, cookie management, stream utilities for handling readable/writable streams, file upload handlers for multipart form data processing, and global polyfills for web standards in Node.js environments.

Package Information

  • Package Name: @remix-run/node
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @remix-run/node

Core Imports

import {
  createFileSessionStorage,
  unstable_createFileUploadHandler,
  installGlobals,
  writeReadableStreamToWritable,
  createRequestHandler,
  json
} from "@remix-run/node";

For CommonJS:

const {
  createFileSessionStorage,
  unstable_createFileUploadHandler,
  installGlobals,
  writeReadableStreamToWritable,
  createRequestHandler,
  json
} = require("@remix-run/node");

Basic Usage

import { installGlobals, createFileSessionStorage, json } from "@remix-run/node";

// Install web standard globals in Node.js
installGlobals();

// Create file-based session storage
const sessionStorage = createFileSessionStorage({
  dir: "./sessions",
  cookie: {
    name: "__session",
    maxAge: 86400,
    httpOnly: true,
    secure: process.env.NODE_ENV === "production"
  }
});

// Use in a Remix route
export async function loader({ request }: LoaderFunctionArgs) {
  const session = await sessionStorage.getSession(
    request.headers.get("Cookie")
  );
  
  return json({
    user: session.get("user")
  });
}

Architecture

@remix-run/node is built around several key components:

  • Global Polyfills: Web standard APIs (fetch, Request, Response) for Node.js environments
  • Session Storage: File-based session persistence with automatic cleanup of expired sessions
  • Upload Handling: File upload processing with disk storage and size limits
  • Stream Utilities: Bridges between Node.js streams and Web Streams API
  • Server Runtime: Complete re-export of @remix-run/server-runtime for unified API access

Capabilities

Global Polyfills

Install web standard global APIs in Node.js environments using either undici or @remix-run/web-fetch.

function installGlobals(options?: { nativeFetch?: boolean }): void;

Global Polyfills

Session Storage

File-based session storage that persists session data to the filesystem with automatic expiration handling.

function createFileSessionStorage<Data = SessionData, FlashData = Data>(
  options: FileSessionStorageOptions
): SessionStorage<Data, FlashData>;

interface FileSessionStorageOptions {
  cookie?: SessionIdStorageStrategy["cookie"];
  dir: string;
}

Session Storage

File Upload Handling

Upload handler for processing multipart form data and saving files to disk with configurable options.

function unstable_createFileUploadHandler(
  options?: FileUploadHandlerOptions
): UploadHandler;

class NodeOnDiskFile implements Omit<File, "constructor"> {
  name: string;
  size: number;
  type: string;
  constructor(filepath: string, type: string);
  slice(start?: number, end?: number, type?: string): Blob;
  arrayBuffer(): Promise<ArrayBuffer>;
  stream(): ReadableStream;
  text(): Promise<string>;
  remove(): Promise<void>;
  getFilePath(): string;
}

Upload Handling

Stream Utilities

Utilities for converting between Node.js streams and Web Streams API, enabling seamless data flow between different stream types.

function writeReadableStreamToWritable(
  stream: ReadableStream,
  writable: Writable
): Promise<void>;

function createReadableStreamFromReadable(
  source: Readable
): ReadableStream;

function readableStreamToString(
  stream: ReadableStream<Uint8Array>,
  encoding?: BufferEncoding
): Promise<string>;

function writeAsyncIterableToWritable(
  iterable: AsyncIterable<Uint8Array>,
  writable: Writable
): Promise<void>;

Stream Utilities

Cookie and Session Implementations

Node.js-specific implementations of cookie and session utilities using cookie-signature for secure signing.

function createCookie(name: string, cookieOptions?: CookieOptions): Cookie;

function createCookieSessionStorage<Data = SessionData, FlashData = Data>(
  options: CookieSessionStorageOptions
): SessionStorage<Data, FlashData>;

function createSessionStorage<Data = SessionData, FlashData = Data>(
  options: SessionStorageOptions<Data, FlashData>
): SessionStorage<Data, FlashData>;

function createMemorySessionStorage<Data = SessionData, FlashData = Data>(
  options?: MemorySessionStorageOptions
): SessionStorage<Data, FlashData>;

Cookie and Session Implementations

Server Runtime API

Complete re-export of @remix-run/server-runtime providing unified access to all Remix server functionality including request handling, response utilities, and data fetching.

function createRequestHandler(build: ServerBuild): RequestHandler;

function json<T>(object: T, init?: ResponseInit): TypedResponse<T>;

function defer<T>(object: T, init?: ResponseInit): TypedDeferredData<T>;

function redirect(url: string, init?: number | ResponseInit): Response;

Server Runtime API