{"id":25687523,"url":"https://github.com/fbbdev/node-fastcgi","last_synced_at":"2025-04-05T12:02:23.834Z","repository":{"id":12636676,"uuid":"15308129","full_name":"fbbdev/node-fastcgi","owner":"fbbdev","description":"Create FastCGI applications with node.js","archived":false,"fork":false,"pushed_at":"2025-02-14T00:08:52.000Z","size":151,"stargazers_count":68,"open_issues_count":3,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T11:06:45.696Z","etag":null,"topics":["backend","fastcgi","fcgi","javascript","node","nodejs","server"],"latest_commit_sha":null,"homepage":"https://fbbdev.it/projects/node-fastcgi","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fbbdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-19T09:52:28.000Z","updated_at":"2025-03-28T21:53:41.000Z","dependencies_parsed_at":"2025-03-22T10:04:14.896Z","dependency_job_id":"15855ccd-335b-4c3d-b5d9-15bdee675693","html_url":"https://github.com/fbbdev/node-fastcgi","commit_stats":{"total_commits":121,"total_committers":6,"mean_commits":"20.166666666666668","dds":"0.19834710743801653","last_synced_commit":"3906e170e8100b521c8631262541be80d69db6de"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbbdev%2Fnode-fastcgi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbbdev%2Fnode-fastcgi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbbdev%2Fnode-fastcgi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbbdev%2Fnode-fastcgi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fbbdev","download_url":"https://codeload.github.com/fbbdev/node-fastcgi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332559,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","fastcgi","fcgi","javascript","node","nodejs","server"],"created_at":"2025-02-24T20:18:42.046Z","updated_at":"2025-04-05T12:02:23.807Z","avatar_url":"https://github.com/fbbdev.png","language":"JavaScript","readme":"# node-fastcgi\n\n[![Test Status](https://github.com/fbbdev/node-fastcgi/actions/workflows/test.yml/badge.svg)](https://github.com/fbbdev/node-fastcgi/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/fbbdev/node-fastcgi/badge.svg?branch=master)](https://coveralls.io/github/fbbdev/node-fastcgi?branch=master)\n[![Published version](https://img.shields.io/npm/v/node-fastcgi)](https://www.npmjs.com/package/node-fastcgi)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n\nThis module is a drop-in replacement for node's standard http module (server only). Code written for a http server should work without changes with FastCGI. It can be used to build FastCGI applications or to convert existing node applications to FastCGI.\n\nThe implementation is fully compliant with the [FastCGI 1.0 Specification](https://fast-cgi.github.io/spec).\n\n## Example\n\n```javascript\nvar fcgi = require('node-fastcgi');\n\nfcgi.createServer(function(req, res) {\n  if (req.method === 'GET') {\n    res.writeHead(200, { 'Content-Type': 'text/plain' });\n    res.end(\"It's working\");\n  } else if (req.method === 'POST') {\n    res.writeHead(200, { 'Content-Type': 'text/plain' });\n    var body = \"\";\n\n    req.on('data', function(data) { body += data.toString(); });\n    req.on('end', function() {\n      res.end(\"Received data:\\n\" + body);\n    });\n  } else {\n    res.writeHead(501);\n    res.end();\n  }\n}).listen();\n```\n\n## Server constructor\n\nThe `createServer` function takes four **optional** parameters:\n\n  - `responder`: callback for FastCGI responder requests (normal HTTP requests, listener for the `'request'` event).\n  - `authorizer`: callback for FastCGI authorizer requests (listener for the `'authorize'` event)\n  - `filter`: callback for FastCGI filter requests (listener for the `'filter'` event)\n  - `config`: server configuration\n\n`config` is an object with the following defaults:\n\n```js\n{\n  maxConns: 2000,\n  maxReqs: 2000,\n  multiplex: true,\n  valueMap: {}\n}\n```\n\n`maxConns` is the maximum number of connections accepted by the server. This limit is not enforced, it is only used to provide the FCGI_MAX_CONNS value when queried by a FCGI_GET_VALUES record.\n\n`maxReqs` is the maximum number of total concurrent requests accepted by the server (over all connections). The limit is not enforced, but compliant clients should respect it, so do not set it too low. This setting is used to provide the FCGI_MAX_REQS value.\n\n`multiplex` enables or disables request multiplexing on a single connection. This setting is used to provide the FCGI_MPXS_CONNS value.\n\n`valueMap` maps FastCGI value names to keys in the `config` object. For more information read [the next section](#fastcgi-values)\n\n## FastCGI values\n\nFastCGI clients can query configuration values from applications with FCGI_GET_VALUES records. Those records contain a sequence of key-value pairs with empty values; the application must fetch the corresponding values for each key and send the data back to the client.\n\nThis module retrieves automatically values for standard keys (`FCGI_MAX_CONNS`, `FCGI_MAX_REQS`, `FCGI_MPXS_CONNS`) from server configuration.\n\nTo provide additional values, add them to the configuration object and add entries to the `valueMap` option mapping value names to keys in the config object. For example:\n\n```js\nfcgi.createServer(function (req, res) { /* ... */ }, {\n    additionalValue: 1350,\n    valueMap: {\n        'ADDITIONAL_VALUE': 'additionalValue'\n    }\n});\n```\n\n**WARNING: The `valueMap` API is a bad design choice and is going to change in the future.**\n\n## Listening for connections\n\nWhen a FastCGI service is started, the stdin descriptor (fd 0) [is replaced by a bound socket](https://fast-cgi.github.io/spec#accepting-transport-connections). The service application can then start listening on that socket and accept connections.\n\nThis is done automatically when you call the `listen` method on the server object without arguments, or with a callback as the only argument.\n\nThe `isService` function is provided to check whether the listen method can be\ncalled without arguments. **WARNING: The function always returns false on\nwindows.**\n\n```js\nif (fcgi.isService()) {\n    fcgi.createServer(/* ... */).listen();\n} else {\n    console.log(\"This script must be run as a FastCGI service\");\n}\n```\n\n## Request URL components\n\nThe `url` property of the request object is taken from the `REQUEST_URI` CGI variable, which is non-standard. If `REQUEST_URI` is missing, the url is built by joining three CGI variables:\n\n  - [`SCRIPT_NAME`](https://tools.ietf.org/html/rfc3875#section-4.1.13)\n  - [`PATH_INFO`](https://tools.ietf.org/html/rfc3875#section-4.1.5)\n  - [`QUERY_STRING`](https://tools.ietf.org/html/rfc3875#section-4.1.7)\n\nFor more information read [section 4.1](https://tools.ietf.org/html/rfc3875#section-4.1) of the CGI spec.\n\nRaw CGI variables can be accessed through the `params` property of the socket object. More information [here](#the-socket-object).\n\n## Authorizer and filter requests\n\nAuthorizer requests may have no url. Response objects for the authorizer role come with the `Content-Type` header already set to `text/plain` and expose three additional methods:\n\n  - `setVariable(name, value)`: sets CGI variables to be passed to subsequent request handlers.\n  - `allow()`: sends a 200 (OK) status code and closes the response\n  - `deny()`: sends a 403 (Forbidden) status code and closes the response\n\nFilter requests have an additional data stream exposed by the `dataStream` property of [the socket object](#the-socket-object) (`req.socket.dataStream`).\n\n## The socket object\n\nThe socket object exposed in requests and responses implements the `stream.Duplex` interface. It exposes the FastCGI stdin stream (request body)\nand translates writes to stdout FastCGI records.\nThe object also emulates the public API of `net.Socket`. Address fields contain HTTP server and client address and port (`localAddress`, `localPort`, `remoteAddress`, `remotePort` properties and the `address` method).\n\nThe socket object exposes three additional properties:\n  - `params` is a dictionary of raw CGI params.\n  - `dataStream` implements `stream.Readable`, exposes the FastCGI data stream for the filter role.\n  - `errorStream` implements `stream.Writable`, translates writes to stderr FastCGI Records.\n\n## http module compatibility\n\nThe API is almost compatible with the http module from node v0.12 all the way to v6.x (the current series). Only the server API is implemented.\n\nDifferences:\n  - A FastCGI server will never emit `'checkContinue'` and `'connect'` events because `CONNECT` method and `Expect: 100-continue` headers should be handled by the front-end http server\n  - The `'upgrade'` event is not currently implemented. Typically upgrade/websocket requests won't work with FastCGI applications because of input/output buffering.\n  - `server.listen()` can be called without arguments (or with a callback as the only argument) to listen on the default FastCGI socket `{ fd: 0 }`.\n  - `server.maxHeadersCount` is useless\n  - `req.socket` [is not a real socket](#the-socket-object).\n  - `req.trailers` will always be empty: CGI scripts never receive trailers\n  - `res.writeContinue()` works as expected but should not be used. See first item\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Fabio Massaioli and other contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbbdev%2Fnode-fastcgi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffbbdev%2Fnode-fastcgi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbbdev%2Fnode-fastcgi/lists"}