Connect-Next Middleware Framework

4.0.1 · active · verified Sun Apr 19

connect-next is an actively maintained fork of the classic Connect middleware framework for Node.js, providing a high-performance, pluggable HTTP server framework built around a "middleware" stack. The current stable version is 4.0.1, released as part of an active development cadence. Key differentiators from the original Connect include a complete rewrite in TypeScript, native ES module (ESM) publication, and a stricter Node.js engine requirement (currently `^20.19.0 || >=22.12.0`). It also ships with its own TypeScript types, eliminating the need for `@types/connect`. The project modernizes the proven Connect architecture, ensuring compatibility with contemporary Node.js practices and providing a robust foundation for web applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a basic Connect-Next application, adding common middleware for compression, session management, and body parsing, then listening for HTTP requests.

import { connect } from 'connect-next';
import { createServer } from 'node:http';
import compression from 'compression';
import cookieSession from 'cookie-session';
import bodyParser from 'body-parser';

const app = connect();

// gzip/deflate outgoing responses
app.use(compression());

// store session state in browser cookie
app.use(
  cookieSession({
    keys: ['secret1', 'secret2'],
  }),
);

// parse urlencoded request bodies into req.body
app.use(bodyParser.urlencoded({ extended: false }));

// respond to all requests
app.use((req, res) => {
  res.end('Hello from Connect!\n');
});

// create an HTTP server and listen on port 3000
createServer(app).listen(3000);

view raw JSON →