Documentation.

Basics Quick Start with Node.js

Sections

Basics

  1. Quick Start Guide
  2. Quick Start with Node.js
  3. Theming

Development

  1. Server Libraries
  2. Database Backends

Code API

  1. Server-side PHP
  2. Node.js Server
  3. Client-Side Scripts
 

Note

The Node.js server only works on VPSes and Ded­i­cated servers; it will not work on shared hosts!

Step One: Extrac­tion and Upload

Go down­load the lat­est ver­sion of Ajax IM; the “Mini­fied” copy should be fine for this guide. Once down­loaded, extract the files to any folder on your computer.

After extrac­tion, con­nect to your FTP server and cre­ate a new folder called ajaxim. Upload all of the Ajax IM files into this folder.

Step Two: Installation

Fol­low the instal­la­tion guide. Be sure to select the “Node.js” or “Node.js (Guests)” server library. Once you’ve run the installer, move on to step three.

Step Three: Initialization

Great, you’ve installed Ajax IM! Now what?

Place the load­ing code in the header or footer of your website.

<script type="text/javascript" src="publicpathtoajaxim/js/im.load.js?node"></script>

Notes:

  • publicpathtoajaxim should be the pub­licly avail­able path to your Ajax IM instal­la­tion, e.g. /ajaxim.
  • If you are using the “Guests” library instead of the reg­u­lar Node.js library, replace ?node with ?guest

 

Place this code on your web­site, either in the <head> sec­tion or before </body> (fre­quently in a header or footer file). It will auto­mat­i­cally load any nec­es­sary libraries (jQuery, etc.) and the main Ajax IM script, im.js. Addi­tion­ally, it will auto­mat­i­cally ini­tial­ize the Ajax IM class for you.

You can find out more about the indi­vid­ual ini­tial­iza­tion options by read­ing the im.js doc­u­men­ta­tion.

Step Four: Allow­ing users to reg­is­ter and login

If you are using the “Guests” library, you can skip directly to step five. Users will auto­mat­i­cally be logged in by the load­ing script.

Now that the IM library will auto­mat­i­cally load on your web­site, you’ll need a way to allow users to login and reg­is­ter. For­tu­nately, Ajax IM pro­vides a very sim­ple function/widget that will han­dle this for you.

To insert a login/registration form, first add the code <div id="ajaxim"></div> some­where on your site.

Below that <div> ele­ment, add the fol­low­ing code

<script type="text/javascript">
    AjaxIM.loaded(function() { AjaxIM.client.form('#ajaxim'); });
</script>

This AjaxIM.client.form func­tion will auto­mat­i­cally load (from your theme) the login and reg­is­tra­tion forms, and insert them into the “ajaxim” ele­ment. This also means that you can insert this form into any ele­ment you would like; just swap “#ajaxim” for the ele­ment id you’d like to use (be sure to pre­fix it with ‘#’, which denotes that we’re refer­ring to an element’s id).

Step Five: Run­ning the Node.js server

First, please install the Node.js application.

Since instal­la­tion should have auto­mat­i­cally con­fig­ured the Node.js server for you, all you need to do to run the Node.js server is nav­i­gate to the “server” folder and exe­cute the fol­low­ing com­mand on your com­mand line:

node server.js

That’s all there is to it! If you would like to see debug mes­sages (which will print data every time a user con­nects, dis­con­nects, or exe­cutes an action), open server.js and set this.debug to true instead of false.

1 Comments

  1. by Sunny Singh on February 18, 2010

    I am stuck on step 5. I used the defaults in the instal­la­tion (Default node.js) and am on a shared host. I setup a page and loaded the nec­es­sary JavaScript but noth­ing loaded on the page. How do I get this “Node.js Server” running?

Leave a comment