/cgi-node

CGI Node.js complete module to replace PHP on shared hosting such as GoDaddy

Primary LanguageJavaScriptMIT LicenseMIT

cgi-node

CGI-Node is designed to replace PHP on any shared web hosting site.

CGI-Node provides the ability to run JavaScript on any web server just like PHP as a CGI using Node.js.

Essentially allowing developers to use a single programming language, JavaScript, for both client and server. You can even run the same code (libraries) on the client or server, reducing development time and code base.

CGI-Node run on shared hosting sites running Apache. It can run along side PHP.

Features

  • Complete and easy access to the HTTP Request:
    • url: The node.js URL object.
    • method: GET | POST | ...
    • headers: {name: value, ...}
    • cookies: {name: value, ...}
    • query/forms: {fieldName: fieldValue, ....}
    • POST data such as forms and files
  • Complete and simple HTTP Response interface:
    • headers: get/set/remove response header fields.
    • cookies: full cookies support between client and server (@see sessions)
  • Full server-side Session management:
    • Store cookies on the server.
    • Store any data that persists between every request.
  • Automatic error handling and global exception handler with HTML output to browser.

Easy Setup

  • Download the appropriate Node.js binary from here and copy it to your bin folder on your site.
  • Download cgi-node.js from here and copy it to your cgi-bin folder on your site.
  • Update the first line within cgi-node.js to point to the location of the node executable you uploaded earlier. For example:
    #!/home/mysite/bin/node
  • Ensure you have .htaccess file that contains the following information:
       Action cgi-node /cgi-bin/cgi-node.js 
       AddHandler cgi-node .jss

That's it!

Required Apache Modules:

  • mod_actions
  • mod_cgi

Testing it on your machine

There is a Dockerfile which will download NodeJS, enable the required Apache's Mods, and run port 8080.

Requirements:

  • docker
  • docker-compose
  1. Run:
    docker-compose up
  2. Then access the Url: http://localhost:8080