• About
  • Gallery of Images
  • Archives
  • Categories
  •   Setting up node.js on appfog – a quick tutorial

    25/03/13 - 19:09

    I’ve been playing around with node.js and loving it so far. I wanted to find a third party host for it, as my current host won’t let me play with it without it getting expensive quickly. So after some googling around, I decided to give AppFog a go. It’s free and from my limited exposure to it so far, does the job pretty well. I ran into a few stumbling blocks as I went, so decided to put a mini-tutorial together to explain how to get node.js running.

    Firstly, you need to sign up to an account. No credit/debit card details needed. Once signed in, you need to go here : https://console.appfog.com/apps/new. Simple enough. To get an instance running, simply select node.js from the first menu :

    Then select where you want it hosted, followed by giving the app a name :

    Once done, click on Create App, and you are re-directed to something similar to this screen :

    Congratulations! You have just created a node.js instance. Now, with a process as simple as that, why on earth do I need to write a tutorial? Well, I spent some time sorting out the environment to properly edit this instance, so this is the ‘meat’ of the tutorial.

    Firstly, you need to install ruby. http://rubyforge.org/frs/download.php/76804/rubyinstaller-2.0.0-p0.exe should run fine. Install it, and then from the Ruby 2.0.0-pl folder, select start Command Prompt with Ruby.


    cd\
    cd\Ruby200
    mkdir src
    gem update --system
    gem install af
    af login
    cd src
    af pull slimetutorial
    cd slimetutorial
    dir

    This basically creates a /src/ directory within your ruby install and sets everything up nicely. AppFog tutorial suggest an af update – but if you have nothing created already, it just deletes the instance – d’oh! Presuming the above works you should see something very similar to this :

    That file is your node.js file. Open it up in your environment, and lets change the code slightly :


    var http = require('http');
    http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Many happy slime monsters from AppFog.com !');
    }).listen(process.env.VMC_APP_PORT || 1337, null);

    Silly I know πŸ™‚ but anyway, you have this file now saved, how do you deploy it ?

    Simply run an update :


    af update slimetutorial

    If everything went ok, it should look like this :

    This handles stopping the node.js instance, staging it, then re-starting the server. Assuming no errors of course πŸ™‚ Things may look slightly different if your server is started/stopped – visit your control panel and click on the Visit Live Site button. Congratulations, you can now start playing to your hearts content with node.js – for free ! πŸ™‚

    lamentconfig
    Share

    One Response to “Setting up node.js on appfog – a quick tutorial”

    1. Esau says:

      Thank you very much! You helped me a lot πŸ™‚

    Your Reply


    %d bloggers like this: