Skip to content
An http/stack/connect layer to invoke and serve CGI executables.
Perl JavaScript
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


An http/stack/connect layer to invoke and serve CGI executables.

This module implements RFC 3875, and offers an easy interface to run and serve CGI executables using Node's HTTP server. I wrote this so I could directly serve GitWeb through Node.

CGI Scripts?

If you're not familiar with CGI scripts, they're simply executables files that get invoked by a web server with client requests. The script has Environment Variables set that indicate information about the HTTP request the client has sent.

Here's what a simple "Hello World" CGI script in sh would look like:


# Headers are written first. The special "Status" headers
# indicates the response status code
echo "Status: 200"
echo "Content-Type: text/plain"

# Followed by a response body
echo "Hello World!"

Let's call it hello.cgi. Be sure to make it executable with chmod +x hello.cgi!

Invoking "The Script" with Node

Now, we need to set up our Node HTTP server. For every request sent to the server, our hello.cgi script will be invoked, and the response will be sent back to the HTTP client:

var http = require('http');
var cgi = require('cgi');


This will set up a CGI handler with the default options.

Something went wrong with that request. Please try again.