{"id":17729,"library":"jsgi-node","title":"JSGI Middleware Adapter for Node.js","description":"This package, `jsgi-node`, functions as an adapter to execute JSGI (JavaScript Gateway Interface) middleware within the Node.js environment. It specifically implements the JSGI 0.3 specification, which includes support for promise-based asynchronous operations, aligning with Node.js's non-blocking I/O model. JSGI is an asynchronous middleware interface conceived with design principles akin to WSGI in Python or Rack in Ruby, promoting straightforward and efficient middleware connectivity through JavaScript closures. While `jsgi-node` itself does not bundle JSGI components, it provides the runtime necessary for existing JSGI middleware stacks, often found in older projects such as Pintura. The package, currently at version 0.3.3, received its last significant updates over a decade ago. It is considered an abandoned project, primarily of historical interest, and is generally unsuitable for contemporary Node.js application development due to its reliance on an outdated CommonJS draft specification.","status":"abandoned","version":"0.3.3","language":"javascript","source_language":"en","source_url":"https://github.com/kriszyp/jsgi-node","tags":["javascript"],"install":[{"cmd":"npm install jsgi-node","lang":"bash","label":"npm"},{"cmd":"yarn add jsgi-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsgi-node","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides an A+ promise implementation, specifically `promised-io/fs` for asynchronous file system operations, which `jsgi-node` integrates directly into its body streaming.","package":"promised-io","optional":false},{"reason":"Provides supplementary JSGI components like `jsgi/node` (for Node.js HTTP app integration) and `jsgi/ws-jsgi` (for WebSocket handling), which `jsgi-node` expects to delegate to.","package":"jsgi","optional":false},{"reason":"Required as a peer dependency for `jsgi/ws-jsgi` to enable WebSocket functionality with a JSGI application.","package":"node-websocket-server","optional":true}],"imports":[{"note":"This package is CommonJS-only and does not support ES modules. The `start` function directly launches the JSGI server with an application.","wrong":"import { start } from 'jsgi-node'","symbol":"start","correct":"const { start } = require('jsgi-node')"},{"note":"The `Listener` function adapts a JSGI application into a standard Node.js HTTP request listener, suitable for `http.createServer()`.","wrong":"import { Listener } from 'jsgi-node'","symbol":"Listener","correct":"const { Listener } = require('jsgi-node')"},{"note":"This symbol is from the companion `jsgi` package, not `jsgi-node` itself. It allows wrapping a standard Node.js HTTP handler within a JSGI middleware stack.","wrong":"import { Node } from 'jsgi/node'","symbol":"Node","correct":"const { Node } = require('jsgi/node')"}],"quickstart":{"code":"const http = require(\"http\");\nconst jsgiNode = require(\"jsgi-node\");\n\n// Define a simple JSGI application that responds with \"Hello World!\"\n// A JSGI application is a function that takes a request object and returns a promise\n// that resolves to a response object.\nconst myJsgiApp = function(request){\n  console.log(`[${new Date().toISOString()}] Received request: ${request.method} ${request.url}`);\n  return Promise.resolve({\n    status: 200,\n    headers: { \"Content-Type\": \"text/plain\" },\n    body: [\"Hello World from JSGI-Node! Your path was: \" + request.pathInfo]\n  });\n};\n\n// Use jsgi-node's Listener to adapt the JSGI app for Node.js's http.createServer\nconst server = http.createServer(jsgiNode.Listener(myJsgiApp));\n\nconst PORT = process.env.PORT ?? 3000;\nserver.listen(PORT, () => {\n  console.log(`JSGI-Node server listening on http://localhost:${PORT}`);\n  console.log(\"Access the server in your browser or with curl.\");\n});\n\n// To gracefully shut down the server in a real application\nprocess.on('SIGINT', () => {\n  console.log('Server shutting down...');\n  server.close(() => {\n    console.log('Server gracefully stopped.');\n    process.exit(0);\n  });\n});","lang":"javascript","description":"Demonstrates how to create a basic \"Hello World\" JSGI application and host it as a standard Node.js HTTP server using `jsgi-node`'s `Listener` function, including server startup and graceful shutdown."},"warnings":[{"fix":"Migrate to a modern middleware framework like Express, Koa, or Fastify. This package is not viable for contemporary development.","message":"This package is built for an ancient Node.js environment (likely Node.js 0.x - 0.10) and the CommonJS JSGI 0.3 draft specification. It is fundamentally incompatible with modern Node.js versions (e.g., Node.js 14+) without significant polyfills, transpilation, or direct code modification, especially regarding `Buffer` and stream APIs.","severity":"breaking","affected_versions":">=0.3.3"},{"fix":"Use `const pkg = require('jsgi-node')` in CommonJS modules. For ESM, consider using `import pkg from 'jsgi-node'` after configuring `node`'s `--experimental-json-modules` or `createRequire` for interoperability, though compatibility issues with the underlying code will persist.","message":"`jsgi-node` is a CommonJS-only package. Attempting to `import` it in an ES module context will result in errors. Direct interop with modern ESM projects will require bundlers or explicit `createRequire` usage.","severity":"gotcha","affected_versions":">=0.3.3"},{"fix":"Adopt modern, actively maintained middleware standards and frameworks (e.g., Express, Koa).","message":"The underlying JSGI specification itself is a deprecated, unmaintained draft standard from the early CommonJS era. There is no active community support or development for JSGI middleware, severely limiting available components and expertise.","severity":"deprecated","affected_versions":">=0.3.3"},{"fix":"Replace with an actively maintained HTTP server or middleware solution.","message":"The package is abandoned and has not been updated in over a decade. It contains unpatched bugs, security vulnerabilities (CVEs), and design patterns that are likely insecure or inefficient by modern standards. Do not use in production.","severity":"breaking","affected_versions":">=0.3.3"},{"fix":"Ensure the promise library used (e.g., `promised-io`) is present and correctly integrated. For custom promise objects, verify they strictly adhere to Promises/A+ specification.","message":"The promise implementation expected by JSGI 0.3 for request bodies and asynchronous responses may not be fully compatible with native `Promise` in modern Node.js, potentially leading to `UnhandledPromiseRejectionWarning` or unexpected behavior if not using a specific A+ compatible library like `promised-io`.","severity":"gotcha","affected_versions":">=0.3.3"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Run `npm install jsgi-node` in your project directory.","cause":"The `jsgi-node` package has not been installed or is not resolvable in the current Node.js environment.","error":"Error: Cannot find module 'jsgi-node'"},{"fix":"Ensure your file is a CommonJS module (e.g., a `.js` file without `\"type\": \"module\"` in `package.json`) and use `const jsgiNode = require('jsgi-node');`.","cause":"Attempting to use `require()` in an ES module context (e.g., a file ending in `.mjs` or when `\"type\": \"module\"` is set in `package.json`), or attempting to use `import` for this CommonJS-only package.","error":"TypeError: require(...) is not a function"},{"fix":"Ensure the incoming request body is correctly parsed and passed to the JSGI app, and that any promise for `request.body` resolves to an iterable suitable for `join()`. This often implies issues with how input streams are handled or promised.","cause":"The `request.body` object (expected to be an array of buffers/strings that can be joined or a promise resolving to one) is not in the expected format or the promise has not resolved.","error":"TypeError: request.body.join is not a function"},{"fix":"Ensure all promises, especially those returned by your JSGI application, include `.catch()` handlers to explicitly manage errors. Review the promise implementation if `promised-io` or similar is not explicitly used.","cause":"A promise returned by the JSGI application or an internal component rejected without a `.catch()` handler, which is common in older promise patterns not fully compatible with modern Node.js's strict unhandled rejection warnings.","error":"(node:XXXXX) UnhandledPromiseRejectionWarning: Unhandled promise rejection."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}