Development Server
js-cgi includes a built-in development server for local development. No Apache or Nginx required — just run your scripts and see the results in your browser.
Starting the Server
# Start on default port (8000)
js-cgi --serve
# Specify a port
js-cgi --serve 3000
# Specify host and port
js-cgi --serve 0.0.0.0:8080
# Specify a document root
js-cgi --serve 8000 /path/to/project
# With a custom ini file
js-cgi --ini=/path/to/js-cgi.ini --serve 8000
How It Works
.jsfiles are executed through the js-cgi engine- Static files (HTML, CSS, images, fonts, etc.) are served directly
index.jsis used as the directory index (falls back toindex.html)- Each request forks a new process — same isolation as production CGI
- Errors are displayed in the browser and logged to the terminal
Example
Create an index.js file:
const name = request.query.name || "World";
print(`<h1>Hello, ${name}!</h1>`);
Start the server and visit http://localhost:8000/?name=Developer:
$ js-cgi --serve 8000
js-cgi development server
Listening on http://localhost:8000
Document root: /home/user/project
Press Ctrl+C to stop.
[GET] 200 /
Extensions
The dev server loads extensions from the same ini configuration as production. Pass --ini to specify which extensions to load:
js-cgi --ini=/etc/js-cgi/js-cgi.ini --serve 8000
Limitations
The development server is designed for local development only. For production use, deploy with Apache (CGI), Nginx (FastCGI), or use the standalone FastCGI server.