My Server Minimal HTTP Server

2.0.7 · maintenance · verified Sun Apr 19

My Server (npm package `my-server`) is a minimalist, zero-dependency HTTP server for Node.js. It allows developers to quickly set up a simple web server to serve files or respond to HTTP requests with custom handlers. Currently stable at version 2.0.7, the package was last published in January 2020, suggesting a low-cadence or maintenance mode of development, with no significant updates since. Its primary differentiator is its extreme simplicity and lack of external dependencies, making it suitable for lightweight use cases like local development, prototyping, or basic API mocking, without the overhead of larger frameworks.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a basic `my-server` instance, registering a universal handler for all routes, and starting the HTTP server on a specified port, outputting request details as JSON.

const server = require('my-server')();

// Register a universal handler for all incoming requests
server.all(function (req, res) {
  // Log details of the incoming request
  console.log(`Received ${req.method} request for ${req.url}`);
  // Respond with a JSON object containing request details
  res.json({
    headers: req.headers,
    method: req.method,
    range: req.headers.range,
    url: req.url
  }, 0, 2); // The 0 and 2 are indentation arguments for JSON.stringify
});

// Start the server on port 5000
const port = process.env.PORT ?? 5000;
server.listen(port, () => {
  console.log(`My Server is running on http://localhost:${port}`);
  console.log('Access http://localhost:5000/some/path to see response.');
});

view raw JSON →