Registry / web-framework / gateway

gateway

JSON →
library2.0jsnpmunverified

gateway is a Node.js middleware designed to facilitate the execution of CGI scripts, such as PHP files, within a Node.js HTTP server environment. It was initially developed around 2012 to support development tools like Yeoman and Livestyle in serving dynamic content. The package's current stable version is 1.0.0, released over a decade ago, indicating it is no longer actively maintained. Unlike `node-cgi`, `gateway` focuses on serving individual script files rather than `cgi-bin` directories, requiring the corresponding CGI binary (e.g., `php-cgi`) to be installed and accessible in the system's PATH. This approach allows Node.js applications to integrate with existing CGI-based applications but comes with the inherent security and maintenance implications of executing external processes.

npm install gateway
INSTALL
IMPORT
SIG · GATEWAY
G
gateway
web-frameworkjavascriptv2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gateway
const gateway = require('gateway');
import gateway from 'gateway';
This package is a CommonJS module and must be imported using `require()`. It does not support native ESM `import` statements, nor does it provide TypeScript type definitions.

This example sets up a basic Node.js HTTP server using `gateway` to serve a dynamically created `info.php` file, demonstrating how to execute PHP scripts through `php-cgi`.

const http = require('http'); const gateway = require('gateway'); const path = require('path'); const fs = require('fs'); // Create a temporary directory and a PHP file for demonstration const tempDir = path.join(__dirname, 'temp_gateway_test'); if (!fs.existsSync(tempDir)) { fs.mkdirSync(tempDir); } const phpFilePath = path.join(tempDir, 'info.php'); fs.writeFileSync(phpFilePath, `<?php phpinfo(); ?>`); console.log('Created temporary PHP file at:', phpFilePath); console.log('Ensure php-cgi is installed and in your PATH for this example to work.'); const server = http.createServer(gateway(tempDir, { '.php': 'php-cgi' })); const PORT = 3000; server.listen(PORT, () => { console.log(`Gateway server listening on http://localhost:${PORT}`); console.log(`Try visiting http://localhost:${PORT}/info.php`); console.log(`Press Ctrl+C to stop the server and clean up.`); }); // Basic cleanup on exit process.on('SIGINT', () => { console.log('\nShutting down server...'); server.close(() => { if (fs.existsSync(phpFilePath)) { fs.unlinkSync(phpFilePath); } if (fs.existsSync(tempDir)) { fs.rmdirSync(tempDir); } console.log('Cleaned up temporary files. Server stopped.'); process.exit(0); }); });
Debug
Known issues
breakingThis package is considered abandoned and has not been updated in over 10 years. It is highly susceptible to unpatched security vulnerabilities, especially when executing external CGI scripts. Use in production or with untrusted input is strongly discouraged.
fix
Migrate to actively maintained alternatives or use more secure methods for serving dynamic content. If absolutely necessary, thoroughly audit any external scripts executed.
affects: >=1.0.0
gotcha`gateway` explicitly does not support `cgi-bin` directories for script execution. Its design focuses on serving individual script files based on file extension mapping.
fix
If `cgi-bin` functionality is required, consider using alternative packages like `node-cgi` or setting up a dedicated web server (e.g., Nginx, Apache) to handle `cgi-bin`.
affects: >=1.0.0
gotchaThe middleware requires external CGI executables (e.g., `php-cgi`) to be pre-installed on the system and accessible in the system's PATH environment variable. Failure to do so will prevent scripts from executing correctly.
fix
Install the necessary CGI binaries for your scripting language (e.g., `brew install php@XX` for PHP on macOS) and ensure their location is included in your system's PATH.
affects: >=1.0.0
gotchaWhen a URL points to a valid directory but does not end with a trailing slash, `gateway` will issue a permanent (301) redirect to append the slash. This behavior may impact routing or caching strategies.
fix
Be aware of this redirect behavior in your application's routing. Ensure client requests for directories include a trailing slash if redirects are undesired.
affects: >=1.0.0
gotchaThis package is a CommonJS module and does not natively support ES Modules (ESM) `import` syntax. It also does not ship with TypeScript type definitions.
fix
Always use `const gateway = require('gateway');` for importing. For TypeScript projects, you may need to create a custom declaration file (`.d.ts`) if type safety is desired.
affects: >=1.0.0
Errors
Common errors & fixes
Error: spawn <cgi-binary-name> ENOENT
The specified CGI executable (e.g., `php-cgi`) cannot be found in the system's PATH.
fix
Install the required CGI binary and ensure its installation directory is correctly added to your system's PATH environment variable.
PHP script content displayed as plain text in the browser.
`gateway` is serving the PHP file content directly instead of executing it, likely due to a misconfiguration in the file extension mapping or the `php-cgi` binary not functioning.
fix
Verify that the `gateway` options correctly map the file extension (e.g., `'.php': 'php-cgi'`) and confirm that the CGI binary (e.g., `php-cgi`) is installed and can execute the script from the command line.
TypeError: gateway is not a function
Attempting to import the CommonJS `gateway` module using an ESM `import` statement in an ESM context, leading to an incorrect module resolution.
fix
Use the CommonJS `require` syntax: `const gateway = require('gateway');`.
Upgrade
Version history
2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
7
Resources
gateway — npm install gateway · libregistry