Common HTTP/HTTPS/SPDY Server API

1.0.2 · abandoned · verified Sun Apr 19

The `create-server` package provides a unified API for establishing HTTP, HTTPS, and SPDY servers in Node.js, aiming to simplify common server setup patterns. It handles the boilerplate for configuring server instances, including providing a callback-based interface for various server events (close, request, upgrade, listening, error, etc.). The library, last updated in April 2019 at version 1.0.2, notably features built-in 'sane defaults' for security against older threats like POODLE and Heartbleed, and allows custom overrides for ciphers and protocols. However, its primary differentiator, SPDY support, is now largely obsolete in favor of HTTP/2 and HTTP/3. Given its age, the package is likely to lack support for modern JavaScript features like native ESM and may contain security defaults that are no longer considered best practice against contemporary threats.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a basic HTTP server using `create-server` on port 3000, handling incoming requests, and logging server events. Includes graceful shutdown.

const create = require('create-server');
const http = require('http'); // Node.js built-in HTTP module

const server = create({
    port: process.env.PORT || 3000,
    hostname: '127.0.0.1',
    // Optional: redirect HTTP to HTTPS
    // redirect: 80,
    // For HTTPS/SPDY, you'd add 'key', 'cert', 'ca', 'spdy: true' options
}, {
    request: function (req, res) {
        console.log(`Received request for: ${req.url}`);
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end('Hello from create-server!\n');
    },
    listening: function (err) {
        if (err) {
            console.error('Server failed to start:', err);
            return;
        }
        console.log(`Server listening on http://${server.hostname}:${server.port}`);
    },
    error: function (err) {
        console.error('Server error:', err);
    }
});

// To stop the server gracefully
process.on('SIGINT', () => {
    console.log('Stopping server...');
    server.close(() => {
        console.log('Server stopped.');
        process.exit(0);
    });
});

view raw JSON →