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
  • request and response globals for handling HTTP
  • print() to output content and include() 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

PlatformArchitecturesStatus
Linuxx86_64, arm64Available
macOSx86_64, arm64Coming soon
Windowsx86_64Coming soon
Was this page helpful?