npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cgi-script

v1.0.0

Published

An http-like API for running nodejs as CGI application

Downloads

5

Readme

Allows you to run nodejs as Common Gateway Interface (CGI) script by some other process (e.g. apache or another instance of nodejs), rather than acting as a standalone HTTP server, while using an API familiar from the http module. Its main intent is to allow the same application to be run either way.

HTTP request headers are read from process.env and the request body is read from process.stdin. Response headers and body are written to process.stdout. For more information about the Common Gateway interface, see RFC 3875.

This package does the opposite of the cgi package. While the latter allows you to run any CGI script from a nodejs HTTP server, this package allows you to run a nodejs CGI script from any HTTP server.

This package does not provide a full javascript preprocessor as node-cgi does. It intends to do just the minimum to run your applications the usual way, not to provide an entire new way of developing nodejs web applications.

Using cgi-script

Assuming you have a file named helloworld.js:

#!/usr/bin/nodejs

const cgiScript = require('cgi-script');

const server = cgiScript.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen();

Note that the shebang #!/path/to/nodejs is mandatory for most HTTP servers.

To run this using Apache, you could add to your .htaccess file:

<Files helloworld.js>
	SetHandler cgi-script
</Files>

When accessing the URL http://yourserver/path/to/helloworld.js, you would receive a plaintext file containing the text "Hello World".

Package Contents

  • cgiScript.createServer - creates a fake HTTP server
  • cgiScript.Server - a fake HTTP server that serves the CGI request
  • cgiScript.Request - a http.IncomingMessage reading headers from process.env
  • cgiScript.Response - a http.ServerResponse writing the response in CGI format (basically, replaces HTTP 200 OK by Status: 200 OK)
  • cgiScript.Socket - a stream.Duplex reading from process.stdin and writing to process.stdout

Documentation

Additional documentation is provided using jsdoc.

See Also

  • RFC 3875 - The Common Gateway Interface (CGI) Version 1.1
  • http - NodeJS HTTP interface.
  • process - NodeJS process interface.
  • cgi - An http/stack/connect layer to invoke and serve CGI executables.
  • node-cgi - Node as CGI-module. Proof of concept.