http-server-plus
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
An augmented Node.js HTTP server that supports HTTP, HTTPS, and HTTP/2 on the same instance, with the ability to listen on multiple ports, sockets, or file descriptors simultaneously. Version 1.0.0 is stable with irregular release cadence. Key differentiators include unified server creation via `create()`, promise-based `.listen()` with nice addresses, and built-in support for HTTP/2 via `http2` (Node >=8) or `spdy` (Node <8). Suitable for advanced server setups needing multiple protocols or endpoints.
Common errors
error TypeError: Cannot read property 'create' of undefined ↓
cause Incorrect import of default export when expecting named export in CommonJS.
fix
Use
const { create } = require('http-server-plus'); error Error: The server could not listen on ... ↓
cause Hostname or port already in use, missing certificates, or invalid socket path.
fix
Check error.niceAddress for details; ensure ports are free, certificates exist, and sockets paths are valid.
Warnings
breaking listen() now returns a Promise instead of the server object ↓
fix Use async/await or .then() to handle the Promise returned by listen().
deprecated Support for spdy (HTTP/2 for Node <8) is deprecated, use built-in http2 module ↓
fix For Node >=8, use http2.createSecureServer as shown in docs.
gotcha When calling listen() with multiple options, the Promise returned from each listen() must be awaited ↓
fix Use Promise.all() to await all listen() calls as shown in the example.
Install
npm install http-server-plus yarn add http-server-plus pnpm add http-server-plus Imports
- default export wrong
const httpServerPlus = require('http-server-plus')correctimport httpServerPlus from 'http-server-plus' - create wrong
const create = require('http-server-plus').createcorrectimport { create } from 'http-server-plus' - Server wrong
const Server = require('http-server-plus').Servercorrectimport { Server } from 'http-server-plus'
Quickstart
import { create } from 'http-server-plus';
import express from 'express';
const app = express();
app.get('/', (req, res) => res.send('Hello World'));
const server = create(app);
(async () => {
try {
const addresses = await Promise.all([
server.listen({ hostname: 'localhost', port: 3000 }),
server.listen({ hostname: 'localhost', port: 3001 })
]);
console.log('Server listening on:', addresses);
} catch (err) {
console.error('Failed to start:', err);
}
})();