{"id":11376,"library":"my-server","title":"My Server Minimal HTTP Server","description":"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.","status":"maintenance","version":"2.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/joncasey/my-server","tags":["javascript","http","server"],"install":[{"cmd":"npm install my-server","lang":"bash","label":"npm"},{"cmd":"yarn add my-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add my-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `my-server` package exports a function which must be immediately invoked to get the server instance. This is a CommonJS module and may not work directly with ESM `import` statements without Node.js interoperability features.","wrong":"const myServer = require('my-server');\n// or\nimport { server } from 'my-server';","symbol":"server","correct":"const server = require('my-server')();"},{"note":"The `listen` method is available on the server instance returned by the package's invoked function, not directly on the `require`'d function itself.","wrong":"require('my-server').listen(5000);","symbol":"server.listen","correct":"server.listen(5000);"}],"quickstart":{"code":"const server = require('my-server')();\n\n// Register a universal handler for all incoming requests\nserver.all(function (req, res) {\n  // Log details of the incoming request\n  console.log(`Received ${req.method} request for ${req.url}`);\n  // Respond with a JSON object containing request details\n  res.json({\n    headers: req.headers,\n    method: req.method,\n    range: req.headers.range,\n    url: req.url\n  }, 0, 2); // The 0 and 2 are indentation arguments for JSON.stringify\n});\n\n// Start the server on port 5000\nconst port = process.env.PORT ?? 5000;\nserver.listen(port, () => {\n  console.log(`My Server is running on http://localhost:${port}`);\n  console.log('Access http://localhost:5000/some/path to see response.');\n});","lang":"javascript","description":"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."},"warnings":[{"fix":"Use CommonJS `require()` syntax: `const server = require('my-server')();`. If strictly in an ESM context, consider dynamic `import()` or using a CJS wrapper.","message":"The `my-server` package is a CommonJS module (CJS) and does not natively support ES Modules (ESM) `import` syntax. Attempting to `import` it in a pure ESM context (e.g., in a Node.js project with `\"type\": \"module\"` set in `package.json`) will likely result in an error or require manual interoperability configuration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For critical applications, evaluate the source code for known vulnerabilities or consider more actively maintained HTTP server libraries. For simple development, its stability might be sufficient, but monitor Node.js compatibility.","message":"The `my-server` package has not been updated since January 2020. While a simple file server may not require frequent updates, this indicates a lack of active maintenance, which could lead to compatibility issues with newer Node.js versions or unaddressed security vulnerabilities for production use cases.","severity":"deprecated","affected_versions":">=2.0.7"},{"fix":"Always initialize the server instance by calling the imported function: `const server = require('my-server')();`.","message":"The package exports a function that must be *invoked* (`()`) immediately after `require()` to obtain the server instance. Forgetting to call this function will lead to a `TypeError` when attempting to call methods like `listen` or `all` on the raw function.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the `my-server` function is called: `const server = require('my-server')();`","cause":"The imported `my-server` function was not invoked, so `server` is still a function, not the server instance.","error":"TypeError: server.listen is not a function"},{"fix":"Change the port number passed to `server.listen(PORT)` or terminate the process currently using the port.","cause":"Another process is already using the specified port (e.g., port 5000).","error":"Error: listen EADDRINUSE: address already in use :::5000"},{"fix":"The `my-server` package is CJS-only. To use it in an ESM project, consider a dynamic import (`import('my-server').then(mod => mod() )`) or stick to CommonJS for this part of your application. For new projects, prefer modern ESM-compatible server frameworks.","cause":"Attempting to use `require()` in an ES Module (`.mjs` file or `\"type\": \"module\"` in `package.json`) context.","error":"ReferenceError: require is not defined in ES module scope"}],"ecosystem":"npm"}