npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

low-http-server

v4.2.0

Published

HTTP Server implementation on top of uWebSocket.js

Downloads

38

Readme

low-http-server

Build Status NPM version
HTTP server implementation for Node.js based on uWebSockets.js!

Formerly part of the 0http project!

Introduction

low-http-server is a Node.js wrapper around the great uWebSockets.js library. Here, I/O throughput is maximized at the cost of API compatibility, when we compare it to the standard Node.js HTTP server interface.

As far as Node.js stands, uWebSockets.js brings the best I/O performance in terms of HTTP servers.

const server = require('low-http-server')({})
server.on('request', (req, res) => {
  res.end('Hello World!')
})

server.listen(3000, () => {
  console.log('Server listening on http://0.0.0.0:3000')
})

Or with SSL:

const server = require('low-http-server')({
  cert_file_name: './demos/test.crt',
  key_file_name: './demos/test.key',
  passphrase: 'test'
})

server.on('request', (req, res) => {
  res.end('Hello World!')
})

server.listen(3000, () => {
  console.log('Server listening on http://0.0.0.0:3000')
})

Benchmarks

Machine: MacBook Pro (13-inch, 2020), 1,4 GHz Quad-Core Intel Core i5
Node.js version: 12.18.3

wrk -t8 -c40 -d5s http://127.0.0.1:3000

Take note that low-http-server does not clusterize on anything besides reasonably recent versions of Linux kernel. You may deploy several instances listening on different IPs and being proxied (e.g. by nginx) as a workaround.

Clusterization could be possibly implemented, as soon as uWebSockets.js gets support for listening to a socket.

Known limitations

  • Limited compatibility with Node.js standard interface.

Integrations

General notes

Low-http-server has become more compatible with Node.js standard interface, but it is not perfect. Despite certain quirks, low-http-server can often replace the usual node http module backend and serve as an underlying server for popular node.js frameworks. There are only two known requirements:

  • The framework doesn't rely on deprecated Object.setPrototypeOf to add new properties to the request and response objects. This is because our request and response provide similar APIs, but are inherently different in their internals. They cannot be replaced with an essentialy incompatible foreign Prototype. This means that Express is currently incompatible (see Express init middleware).
  • The HTTP handler function is NOT prioritized using setImmediate . Otherwise, low-http-server will work, but perforfmance will suffer tremendously. For example, in Restana you are going to need prioRequestsProcessing framework option set to false

0http framework

const low = require('low-http-server')
const cero = require('0http')

const { router, server } = cero({
  server: low()
})

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

server.listen(3000, (socket) => {
  if (socket) {
    console.log('HTTP server ready!')
  }
})

restana framework

No problems, if prioRequestsProcessing is set to false.

const server = require('low-http-server')({})

const service = require('restana')({
  server: server,
  prioRequestsProcessing: false // NOTE: required for restana integration
})

server.listen(3000, () => {
  console.log('Server listening on http://0.0.0.0:3000')
})

service.get('/', (req,res) => {
  res.send('It works!')
})

Fastify

  • Broken in current release.

Other frameworks

Please refer to their documentation on how to use your own server.