Zero friction HTTP framework
for Node.js

Tweaked for high throughput, low overhead, and maximum flexibility.

Why 0http?

🚀

Blazing Fast

One of the fastest Node.js web frameworks. Optimized for speed with smart caching and efficient routing.

⚙️

Highly Configurable

Swap routers, servers, and customize behavior to fit your needs. You are in control.

🔌

Middleware Support

Express-like middleware chain with full async/await support for modern development.

ʦ

TypeScript Ready

First-class TypeScript support for type-safe development out of the box.

🧩

Nested Routing

Powerful nested router support for modular architectures, optimized for static paths.

🛡️

Production Ready

Secure defaults with environment-aware error handling. Built for the real world.

Core Capabilities

1. Pluggable Routers

0http allows you to define the router implementation you prefer.

Sequential Router (Default)

An extended implementation of trouter.

  • Features: Middleware support, nested routers, regex matching.
  • Performance: Uses an internal LRU cache (optional) to store matching results, making it extremely fast even with many routes.
  • Supported Verbs: GET, HEAD, PATCH, OPTIONS, CONNECT, DELETE, TRACE, POST, PUT

Find-My-Way Router

Integration with find-my-way, a super-fast Radix Tree router.

  • Best for: Static paths and high performance without regex overhead.
  • Note: Does not support all the middleware goodies of the sequential router.

2. Middleware Engine

The middleware engine is optimized for performance and flexibility.

  • Global & Route Middleware: Define middleware globally or for specific routes.
  • Async/Await Support: Fully supports async middlewares for clean code.

3. Nested Routers

Organize your application with modular nested routers. 0http optimizes static nested routes for better performance.

4. Custom Servers

0http is server-agnostic. You can use the standard Node.js http.Server, https.Server, or even custom implementations.

Configuration Options

Pass a configuration object to zero(config):

Option Description Default
router Custom router instance. sequential()
server Custom server instance. http.createServer()
defaultRoute Handler for 404 Not Found. (req, res) => { res.statusCode = 404; res.end() }
errorHandler Global error handler. Production-safe error handler.
prioRequestsProcessing Use setImmediate to prioritize request processing. true

Sequential Router Options

Option Description Default
cacheSize LRU cache size. 0 to disable, <0 for unlimited. -1 (Unlimited)

Installation

$ npm install 0http

Quick Start

Get started with 0http in seconds. Choose your use case below.

Basic Server

const zero = require('0http')
const { router, server } = zero()

router.get('/hello', (req, res) => {
  res.end('Hello World!')
})

server.listen(3000)

JSON API

router.get('/api/users', (req, res) => {
  res.setHeader('Content-Type', 'application/json')
  res.end(JSON.stringify({
    users: [
      { id: 1, name: 'Alice' },
      { id: 2, name: 'Bob' }
    ]
  }))
})

Middleware Chain

// Global middleware
router.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`)
  return next()
})

// Route middleware
router.get('/protected', auth, handler)

Async/Await Support

router.get('/users/:id', async (req, res) => {
  try {
    const user = await db.findUser(req.params.id)
    res.setHeader('Content-Type', 'application/json')
    res.end(JSON.stringify(user))
  } catch (err) {
    res.statusCode = 404
    res.end('User not found')
  }
})

Nested Routers

const apiRouter = zero().router

apiRouter.get('/users', getUsers)
apiRouter.post('/users', createUser)

// Mount nested router
router.use('/api', apiRouter)

// Routes: /api/users

Error Handling

const { router, server } = zero({
  errorHandler: (err, req, res) => {
    console.error(err)
    res.statusCode = 500
    res.end('Internal Server Error')
  }
})

router.get('/error', () => {
  throw new Error('Oops!')
})

Query Parameters

router.get('/search', (req, res) => {
  // Query params available in req.query
  const { q, page, limit } = req.query
  
  res.setHeader('Content-Type', 'application/json')
  res.end(JSON.stringify({ 
    term: q, 
    page: page || 1,
    limit: limit || 10
  }))
})

// GET /search?q=node&page=2&limit=20

Custom Router

const fmw = require('find-my-way')()

const { server } = zero({
  router: (req, res) => {
    fmw.lookup(req, res)
  }
})

fmw.on('GET', '/fast', (req, res) => {
  res.end('Radix tree routing!')
})

Streaming Response

router.get('/stream', (req, res) => {
  res.setHeader('Content-Type', 'text/plain; charset=utf-8')

  let i = 0
  const interval = setInterval(() => {
    i++
    res.write(`chunk ${i}\n`)

    if (i === 5) {
      clearInterval(interval)
      res.end('done')
    }
  }, 500)
})

Benchmarks

0http is designed for extreme performance.

Performance Benchmarks

Snapshot (MacBook Pro i9, Node v12)

  • 0http (sequential): ~88k req/sec
  • 0http (find-my-way): ~87k req/sec
  • restana: ~73k req/sec

Check the latest independent results: Web Frameworks Benchmark