Skip to content
master
Switch branches/tags
Code

Latest commit

docs(readme): Fixes "NanoExpress" name to "nanoexpress" for accuracy
f9e448e

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

HyperExpress: High Performance Node.js Webserver

Powered by uWebSockets.js

NPM version NPM downloads Language grade: JavaScript GitHub issues GitHub stars GitHub license

Motivation

HyperExpress aims to be a simple yet perfomant HTTP & Websocket Server. Combined with the power of uWebsockets.js, a Node.js binding of uSockets written in C++, HyperExpress allows developers to unlock higher throughput for their web applications with their existing hardware. This can allow many web applications to become much more performant on optimized data serving endpoints without having to scale hardware.

Some of the prominent features implemented are:

  • Simplified HTTP API
  • Simplified Websocket API
  • Asynchronous By Nature
  • Global & Route-Specific Middlewares Support
  • Modular Routers Support
  • HTTP Streaming Support
  • Websocket Streaming Support
  • Global Error/Event Handlers
  • Cryptographically Secure Cookie Signing/Authentication
  • ExpressJS API Compatibility Through Shared Methods/Properties
  • TypeScript Types Support

What's Different?

While there may be other uWebsockets.js based packages available, HyperExpress differentiates itself in the following ways:

  • Instantaneous Request Handling
    • HyperExpress implements a request handling model similar to fetch where a request is passed almost instantly to the route handler and the request body can be asynchronously dowloaded/accessed. This behavior allows for aborting of a request and potentially saving on memory usage for endpoints that deal with relatively larger body sizes as the body simply won't be downloaded into memory without access.
  • Simple To Use API
    • HyperExpress implements simple yet understandable methods/properties for its components to allow for clear and concise code that is at many times chainable and asynchronous.
  • Lightweight Package Size
    • HyperExpress is extremely lightweight while implementing almost all of the core functionalities of a webserver providing users with flexibility.
  • High Maintainability
    • Whether you decide to develop on your own fork or expand upon HyperExpress through middlewares, You will be greeted with a concise codebase with descriptive logic comments and JSDoc types that allow for high maintainability.
  • MIT License
    • Some other webserver packages are released under more restrictive licenses and often provide paid "performance efficient" versions of their package. HyperExpress is provided with a flexible MIT licence in which you are free to expand upon the package as you desire while also being able to take advantage of the efficient and maintainable codebase at no cost.

Installation

HyperExpress can be installed using node package manager (npm)

npm i hyper-express

HyperExpress requires Node.js version 14+

Documentation

  • See > [Examples & Snippets] for small and easy-to-use snippets with HyperExpress.
  • See > [Server] for creating a webserver and working with the Server component.
  • See > [Middlewares] for working with global and route-specific Middlewares in HyperExpress.
  • See > [Router] for working with the modular Router component.
  • See > [Request] for working with the Request component made available through handlers.
  • See > [Response] for working with the Response component made available through handlers.
  • See > [Websocket] for working with Websockets in HyperExpress.
  • See > [SessionEngine] for working with cookie based web Sessions in HyperExpress.
  • See > [LiveDirectory] for implementing static file/asset serving functionality into HyperExpress.

Benchmarks

Below benchmark results were derived using the autocannon HTTP benchmarking utility. The benchmark source code is included in this repository in the benchmarks folder.

CLI Command

This command simulates a high stress situation where 2500 unique visitors visit your website at the same time and their browsers on average make 4 pipelined requests per TCP connection sustained for 30 seconds.

autocannon -c 2500 -d 30 -p 4 http://HOST:PORT/benchmark

Environment Specifications

  • Machine: Ubuntu 20.04 | 1 vCPU | 1GB Mem | 32GB Nvme | Vultr @ $6/Month
  • Node: v16.0.0
  • Method: Two rounds; one to warm-up, one to measure
  • Response Body: Small HTML page with a dynamic timestamp generated with Date. See more in HTML Test.
  • Linux Optimizations: None.

Benchmark Results

Note! uWebsockets.js and HyperExpress were bottlenecked by the network speed of the Vultr instance. While, Fastify and Express were bottlenecked by high CPU usage resulting in a much lower throughput with relatively higher latency numbers. For average use cases, all webservers below can serve requests at lower than 50ms latency.

Version Requests/s Latency Throughput/s
uWebsockets.js 20.0.0 196,721 435 ms 106 Mb/s
HyperExpress 5.0.2 196,833 413 ms 106 Mb/s
nanoexpress 5.1.1 195,728 423 ms 106 Mb/s
Fastify 3.22.0 40,898 565 ms 25 Mb/s
Express 4.17.1 5,791 1740 ms 3.8 Mb/s

Testing Changes

To run HyperExpress functionality tests locally on your machine, you must follow the steps below.

  1. Clone the HyperExpress repository to your machine.
  2. Initialize and pull any submodule(s) which are used throughout the tests.
  3. Run npm install in the root of the HyperExpress repository.
  4. Run npm install in the /tests directory.
  5. Execute the /tests/index.js file to perform tests.

License

MIT