{"id":12008,"library":"server","title":"server.js Node.js Framework","description":"server.js is a Node.js framework designed for building web applications and APIs with a focus on simplicity and ease of use. It provides a comprehensive set of features out-of-the-box, including body and file parsers, cookies, sessions, WebSockets (via Socket.io), Redis integration, gzip compression, favicon handling, CSRF protection, and SSL support. This approach aims to minimize configuration and allow developers to concentrate on business logic. The package is currently stable at version 1.0.42, with frequent minor updates addressing bug fixes and introducing small enhancements, as seen in its recent release history. It differentiates itself by bundling many common utilities that often require separate middleware in other frameworks, while still offering compatibility with the Express middleware ecosystem for extended functionality. It explicitly recommends Node.js 8.x.y LTS or newer (minimum 7.6.0), indicating a CommonJS-first approach in its current major version.","status":"active","version":"1.0.42","language":"javascript","source_language":"en","source_url":"https://github.com/franciscop/server","tags":["javascript","server","node.js","http","websocket","socket","async"],"install":[{"cmd":"npm install server","lang":"bash","label":"npm"},{"cmd":"yarn add server","lang":"bash","label":"yarn"},{"cmd":"pnpm add server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary export is a function to start the server. This package is primarily CommonJS-based.","symbol":"server","correct":"const server = require('server');"},{"note":"Router methods like `get`, `post`, `put`, `del`, `socket` are available via `server.router` or direct import from `server/router`. ESM imports are not officially supported in the 1.x series.","wrong":"import { get, post } from 'server/router';","symbol":"get, post","correct":"const { get, post } = require('server').router;"},{"note":"Reply helper functions for rendering templates or redirecting are found on `server.reply`. ESM imports are not officially supported in the 1.x series.","wrong":"import { render, redirect } from 'server/reply';","symbol":"render, redirect","correct":"const { render, redirect } = require('server').reply;"}],"quickstart":{"code":"const server = require('server');\nconst { get, post } = server.router;\n\n// Launch server with options and a couple of routes\nserver({ port: 8080 }, [\n  get('/', ctx => 'Hello world'),\n  post('/', ctx => {\n    console.log(ctx.data);\n    return 'ok';\n  })\n]);","lang":"javascript","description":"This quickstart code initializes a server listening on port 8080 with a GET route responding 'Hello world' and a POST route logging request data."},"warnings":[{"fix":"Ensure your Node.js environment is within the recommended range or thoroughly test on newer versions for full compatibility.","message":"The package officially supports Node.js versions >=7.6.0 and recommends 8.x.y LTS. While it might run on newer Node.js versions, compatibility beyond Node 8.x LTS is not explicitly guaranteed in the documentation, which could lead to unexpected behavior.","severity":"gotcha","affected_versions":"<=1.0.42"},{"fix":"Update your response handling from `ctx.status(200)` to `ctx.status(200).send()` when no body is intended.","message":"As of version 1.0.12, sending only a status code no longer automatically sets a default body (which was previously handled by Express). To send an empty body with a status, you must explicitly call `.send()` after `.status(NUMBER)`.","severity":"breaking","affected_versions":">=1.0.12"},{"fix":"Adhere to CommonJS `require()` syntax for importing modules and functions from `server`.","message":"The package primarily uses CommonJS `require()` syntax in all documentation and examples. While Node.js supports ESM, `server` does not explicitly document or guarantee full ESM compatibility. Attempting to use `import` statements might lead to module resolution errors or unexpected behavior.","severity":"gotcha","affected_versions":"<=1.0.42"},{"fix":"Upgrade to `server` version 1.0.7 or newer to resolve `path-to-regexp-wrap` inconsistencies with Yarn.","message":"Prior to version 1.0.7, there were inconsistent path resolution issues when using Yarn (compared to npm) with wildcard routes, specifically affecting `path-to-regexp-wrap` behavior.","severity":"gotcha","affected_versions":"<1.0.7"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Explicitly call `.send()` after `.status(NUMBER)`, e.g., `ctx.status(200).send()`.","cause":"Attempting to send an empty body by just setting the status code, which was a behavior change in version 1.0.12.","error":"TypeError: ctx.status(...).send is not a function"},{"fix":"Ensure all route handlers either return a value (which `server` then sends as the response) or explicitly call a response method on the `ctx` object.","cause":"This error or similar warnings (like 'No response was sent from the server') can occur if a route handler does not explicitly return a value or call a response method (e.g., `ctx.send()`, `ctx.render()`, `ctx.redirect()`). Improved error handling for this was added in 1.0.9 and 1.0.13.","error":"Error: No response from the server"},{"fix":"Upgrade `server` to version 1.0.7 or higher. If upgrading is not an option, consider using npm instead of Yarn, or avoid wildcard routes in affected versions.","cause":"Prior to version 1.0.7, there were known issues where wildcard routes (e.g., `get('*', ...)`) behaved differently when `server` was installed via Yarn compared to npm due to `path-to-regexp-wrap` resolution.","error":"Inconsistent routing with '*' wildcard using Yarn"}],"ecosystem":"npm"}