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.
CGI-Node was designed specifically for this purpose. It works on any web hosting service that allows custom CGI scripts. In most cases if your web hosting company uses cPanel then CGI-Node will work.
See this tutorial to get CGI-Node working on GoDaddy.
If you can follow simple instruction then YES. See our GoDaddy tutorial here.
But, if you're a pro then here is the simplified version:
Action cgi-node /cgi-bin/cgi-node.js
AddHandler cgi-node .jss
That's it!
YES, CGI-Node pre-processes all the request headers, query strings, POST data and provides a clean and simple API to access every thing. See the API here.
Like phpInfo(), CgiNodeInfo() will display all the server variables, request headers, query string, POST forms and POST files.
Here is a quick look some of CGI-Node API:
// Writes the given string back to the browser.
write(chunk)
// Includes other .js or .jss files within the current file.
include(path)
// Provides full access to the URL. This object is the Node.js url object.
request.url
// This object contains parsed query string variables. {name: value}
request.query
// This object contains the HTTP request header.
request.header
// This object provides access to the parsed HTTP body (POST)
request.post.form
request.post.files
// This object contains all the response headers.
// You can add, read, or remove headers
before sending them to the client.
response.headers
// This method sends the current headers to the client.
response.sendHeaders()
If you have used PHP before then CGI-Node works exactly the same way. Any requested file from your web-site with .jss extension will be executed on the server using Node.js. CGI-Node uses the same PHP tags to embed JavaScript between your HTML code.
NOTE: Unlike PHP, if you include a .js file then you don't need to wrap the code within <? ?> tags. This will allow you to use the same files on the client/browser without getting syntax errors. This is especially helpful if you have core library or utility methods that can be shared between the server and client.
Here is an example:
<html>
<body>
<?
var helloWorld = 'Hello World!';
write(helloWorld + '<br/>');
?>
<?= helloWorld ?>
<br/>
<b>I can count to 10: </b>
<?
for (var index= 0; index <= 10; index++) write(index + ' '); ?>
<br/>
<b>Or even this: </b>
<?
for (var index= 0; index <= 10; index++) { ?>
<?= index ?>
<? } ?>
</body>
</html>
Results:
Hello World!
Hello World!
I can count to 10: 0 1 2 3 4 5 6 7 8 9 10
Or even this: 0 1 2 3 4 5 6 7 8 9 10
Yes, CGI-Node automatically creates a new session for new users and handles saving and loading session.
Simply store all your session data in session.data and it will persist after every request. See documentation for full details here.
Absolutely, this works the same way as running Node.js locally. You can even use the require() method the same way. For more information about NPM go here: https://www.npmjs.org/
YES!!! this feature is planned and will be release in subsequent versions.
Yes, simply install the MySQL module from NPM.
If you're not sure how, I'l be writing a tutorial on this soon.
YES, cgi-node can not cook you breakfast. YET!