Run CGI-Node.js on GoDaddy Tutorial

Introduction

JavaScript (Node.js) is becoming one of the most popular languages. For some reason today we are still using different languages to develop server side logic than client/browser logic. For example PHP on the server side and JavaScript on the browser. Why not use a single language!!!! You can share code and libraries between client and server. JavaScript is an extremely powerful language but can be tricky to use. With proper commenting and documentation the lack of structure in JavaScript can be remedied.

This tutorial will show you how to install Node.js on one of the most populate Hosting Sites, GoDaddy.com under cPanel. This tutorial should work under any web hosting provider as long as they support custom CGI (Common Gateway Interface).

Let's get started.

Download Required Files

Download Node.js

Download the latest Node.js 64-bit Linux Binaries (.tar.gz) from http://nodejs.org/download/. For this beginner tutorial we will only need /bin/node file inside the downloaded tar file.

Download Node.js

Download CGI-Node.js

Download the latest CGI-Node.js from http://www.cgi-node.org/downloads. You can download the optimized version or the development version. Either will work but the optimized version will give you extra milliseconds on load time.

Download CGI-Node.js

Rename the the downloaded file to cgi-node.js , open it and replace the first line <accountname> with your GoDaddy account name.

Configure GoDaddy

Access cPanel and File Manager

Log into your GoDaddy account and launch the cPanel found under WEB HOSTING.

NOTE: This has only been tested with GoDaddy cPanel hosting and not the legacy hosting which they are trying to phase out.

Go into cPanel

Select "File Manager" to open the "Web Root (public_html/www)". make sure "Show Hidden Files (dotfiles)" is selected as well and hit "Go".

Open file manager

Upload cgi-node.js

Select the "cgi-bin" folder under the "public_html" then click on "Upload"

Select cgi-bin under public_html

This part is very IMPORTANT: make sure the file Permissions is 755 (provide Execute permissions to User, Group, and World) before uploading the file.

IMPORTANT NOTE: You will get an Apache error if the file permissions is not 755.

Upload cgi-node.js

If you forget to change the permissions then you upload the file you can change them later but it is not covered under this tutorial.

Upload Node.js

Now let's upload the downloaded "node" file that we extracted from "node-v0.xx.xx-linux-x64.tar". As of version v0.10.32, the file was around 11MB in size.

Navigate to "/home/<accountname>/bin" folder. Where <accountname> refers to your GoDaddy root home folder.

Upload node.js

Ensure that the permissions is set to 755 like before and upload the "node" executable to the bin folder.

IMPORTANT NOTE: the path to this file must match the first line path in cgi-node.js otherwise you'll get an Apache error.

Upload node.js executable

Adding .htaccess

If you don't already have a ".htaccess" file within public_html then create one. Open ".htaccess" file for editing.

Open .htaccess file for editing

Add the following lines within the file.

Action     cgi-node     /cgi-bin/cgi-node.js 
AddHandler cgi-node     .jscript
Add cgi-node handler to .htaccess file

NOTE: your script extensions do not have to be ".jscript" they can be whatever you want them to be as long as your server side executable scripts have the same extensions.

NOTE: only the entry HTTP request files must have this extension. You can include .js or .jscript files within your code.

We are done, let's test out the script.

Test CGI-Node

Create a new file within the public_html folder called cgiNodeInfo.jscript and add the following code within it. cigNodeInfo() function is does exactly what phpInfo() does, it outputs all the server, environment and request information to the output stream.

<? CgiNodeInfo() ?>

Save the file and navigate to it within your browser and you should see the following:

cgiNodeInfo output results

If you get an error or have any comments let me know. (Comment below)

CGI-Node is still in development and we'd appreciate any feedback or comments to make this module better.

For issue tracking and reporting go to the following link: https://github.com/UeiRicho/cgi-node/issues