Getting Started
js-cgi is a lightweight CGI engine that brings JavaScript to Apache and Nginx as a server-side scripting language. Write .js files, drop them in your web directory, and they execute on every request — outputting HTML, JSON, or whatever you need directly to the browser.
How it Works
When a request hits your web server for a .js file, Apache passes it to the js-cgi binary via the Common Gateway Interface (CGI). js-cgi executes the script and returns the output as the HTTP response.
What You Get
- Full ES2023+ JavaScript support
requestandresponseglobals for handling HTTPprint()to output content andinclude()for shared templates- ES module support with
import/export - Extensions for SQLite, sessions, file I/O, crypto, and HTTP requests
- Memory and execution time limits for safety
- Configurable via a simple ini file
A Simple Example
const name = request.query.name || "World";
print(`<h1>Hello, ${name}!</h1>`);
print(`<p>Requested at: ${new Date().toISOString()}</p>`);
Save this as index.js in your web directory, visit it in a browser, and you'll see the output rendered as HTML.
Platform Support
| Platform | Architectures | Status |
|---|---|---|
| Linux | x86_64, arm64 | Available |
| macOS | x86_64, arm64 | Coming soon |
| Windows | x86_64 | Coming soon |