<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codehenge</title>
	<atom:link href="http://codehenge.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://codehenge.net/blog</link>
	<description>Who built it...and why?&#009;&#009;A blog about software, programming, and technology.</description>
	<lastBuildDate>Tue, 23 Apr 2013 23:28:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Automate Your Development Environment With Vagrant</title>
		<link>http://codehenge.net/blog/2013/02/automate-your-development-environment-with-vagrant/</link>
		<comments>http://codehenge.net/blog/2013/02/automate-your-development-environment-with-vagrant/#comments</comments>
		<pubDate>Sun, 10 Feb 2013 17:12:19 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[automate]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[vagrant]]></category>
		<category><![CDATA[virtualbox]]></category>
		<category><![CDATA[virtualization]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=202</guid>
		<description><![CDATA[Vagrant leverages virtualization and automated system configuration to deliver you customized virtual environments for your development projects. With VirtualBox and its comprehensive API under the hood, Vagrant creates and manages custom virtual environments to your exact specification. But wait, we've been able to create virtual machines for years. What's new here? The problem is configuration of a brand new virtual macine for each project is a massive chore, reinstalling all of your dev tools each time sounds like torture, and developers will still each want VMs of different operating systems...what are we solving? Vagrant does it differently. By giving you the option to leverage powerful, proven automated configuration technologies such as Chef or Puppet (as well as your own custom shell scripts, if you like), Vagrant takes the time and tedium out of configuring a virtual environment]]></description>
				<content:encoded><![CDATA[<p><div id="attachment_203" class="wp-caption alignleft" style="width: 210px"><img class="size-full wp-image-203" alt="100% Certified!" src="http://codehenge.net/blog/wp-content/uploads/2013/02/works-on-my-machine-starburst1-e1359931607861.png" width="200" height="193" /><p class="wp-caption-text">100% Certified!</p></div></p>
<h2>Works on My Machine!</h2>
<p>I&#8217;d like to talk about my favorite software development meme: The 100%, certified, &#8220;Works on my machine!&#8221; build. We&#8217;ve all seen it, and it&#8217;s funny every time. Take a second and consider how many times, in fact, you have seen this situation. You write and test your code thoroughly, and it all goes to hell when you commit to your build environment. Or worse, everything&#8217;s working fine in your staging environment, and something breaks unexpectedly when you push to production. How much frustration can be chalked up such scenarios? How much time have you lost?</p>
<p>Let&#8217;s explore how this phenomenon occurs. The root cause is a lack of parity between environments throughout your software development process. Your development environment is not the same as your test environment. Your staging environment differs from your production environment. This happens naturally, especially with development machines. Developers work on many projects, simultaneously or over the course of time. They pile up applications, libraries, and different versions of tools, much in the same way a basement workshop becomes cluttered after years of home repair projects. Consider your average developer. Maybe they get a new machine and start working on a Java project. They install Java6, Tomcat6, Spring, etc. Then a few more project come along, and Java7, Tomcat7, Python 2.7.2, Django, and C++ are installed. Of course, our developer wants to keep up on the latest in the field, so they also install Node.js, Clojure, MongoDB, Python3, and C++11 to tinker with. And that&#8217;s not to mention other, ahem, <a href="https://minecraft.net/">exercises</a> <a href="http://store.steampowered.com/">in</a> <a href="http://fallout.bethsoft.com/">mental</a> <a href="http://www.worldofwarcraft.com">acuity</a>. Unfortunately, this leads to a fairly cluttered system, with plenty of potential for unanticipated software interactions:</p>
<div>
  <div id="attachment_206" class="wp-caption aligncenter" style="width: 530px"><a href="http://codehenge.net/blog/wp-content/uploads/2013/02/cluttered-system-e1360372808569.png"><img src="http://codehenge.net/blog/wp-content/uploads/2013/02/cluttered-system-e1360372808569.png" alt="Cluttered system" width="520" height="390" class="size-full wp-image-206" /></a><p class="wp-caption-text">What could go wrong?</p></div>
</div>
<p>On top of this, developers prefer different development environments. Some prefer OSX, some windows, some a particular flavor of linux. Just try to get an Ubuntu fan to code in Windows. Go ahead, I&#8217;ll wait. And, of course, different IDEs, tools, debuggers, network configurations&#8230; Each installed application, each change in configuration, causes divergence from the clean operating environment you desire for development and testing. The environment that matches your pristine staging and production servers. So what to do? The ideal solution would create unique, reproducible environments for each project. Each developer&#8217;s environment would be identical, as would the staging and production servers.</p>
<h2>Enter Vagrant&#8230;</h2>
<p><a href="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-e1360203410345.png"><img class="alignright size-full wp-image-204" alt="vagrant" src="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-e1360203410345.png" width="200" height="200" /></a></p>
<p>Vagrant leverages virtualization and automated system configuration to make this dream a reality. With VirtualBox and its comprehensive API under the hood, Vagrant creates and manages custom virtual environments to your exact specification. But wait, we&#8217;ve been able to create virtual machines for years. What&#8217;s new here? The problem is configuration of a brand new virtual macine for each project is a massive chore, reinstalling all of your dev tools each time sounds like torture, and developers will still each want VMs of different operating systems&#8230;what are we solving? Vagrant does it differently. By giving you the option to leverage powerful, proven automated configuration technologies such as <a href="http://www.opscode.com/chef/">Chef</a> or <a href="https://puppetlabs.com/">Puppet</a> (as well as your own custom shell scripts, if you like), Vagrant takes the time and tedium out of configuring a virtual environment. Need a Ruby on Rails development environment? Use <a href="http://community.opscode.com/cookbooks/rails_rvm">this open source Chef cookbook</a> already designed by someone else. Python and Django? <a href="http://community.opscode.com/cookbooks/django">Yo</a>. How about Node.js? Here, <a href="https://github.com/cacois/vagrant-node-mongo">I&#8217;ll give you mine</a>. Don&#8217;t you love FOSS? But your development tools, such as IDEs, browsers, etc, and the preferred operating systems&#8230;this is the best part. By clever use of shared directories and port mapping, Vagrant allows you to keep your code on your host machine, with all of your current tools and apps. You can even run and debug your web application in your own host browser. The VM running in the background, serving up your app, is transparent to you, doing nothing but running your app in a custom, controlled environment.</p>
<p>Let&#8217;s try a quick demo, to make this workflow completely clear. First, download and install <a href="https://www.virtualbox.org/">VirtualBox</a> (if you don&#8217;t have it already) and <a href="http://www.vagrantup.com/">Vagrant</a>. Vagrant will be creating a custom virtual machine for you, based on a configuration i&#8217;ll give you. To do this, Vagrant will need a template, or base VM, to copy and customize. The vagrant dev team is nice enough to provide a number of base linux VMs for our use. To install one, run the following command:</p>
<p><code>$ vagrant box add precise32 http://files.vagrantup.com/precise32.box</code></p>
<p>This will download a base VM of Ubuntu 12.04 32-bit, about 250MB in size, and refer to it by the name &#8220;precise32&#8243;. Next, you&#8217;ll need a project to work on, and a development environment configuration. Here&#8217;s a Node.js demo I have prepared for you. Clone this repository, and move into the project directory:</p>
<p><code>$ git clone https://github.com/cacois/vagrant-node-mongo.git<br />
$ cd vagrant-node-mongo</code></p>
<p>By the way, are you interested in <strong>mastering Node.js</strong>? Check out my online course <a href="http://www.udemy.com/learn-nodejs-by-example/">Learn Node.js by Example</a> for detailed screencasts and example applications. Sign up today from <a href="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">this link and receive 50% off</a>!</p>
<p>Take a look inside this directory.</p>
<pre><code>vagrant-node-mongo / 
   README.md 
   Vagrantfile 
   /app 
   /cookbooks
</code></pre>
<p>Inside the &#8216;app&#8217; subdirectory, I have have a small node.js app that returns some text output to an HTTP request. In &#8216;cookbooks&#8217; are some Chef cookbooks, or collections of recipes that define automated configuration commands to install Node.js, MongoDB, apt-get, and other essential tools. Let&#8217;s take a closer look at the file named &#8216;Vagrantfile&#8217;. This is the Vagrant configuration file, defining how to set up your custom project VM. It should look like this:</p>
<pre><code>Vagrant::Config.run do |config|
  config.vm.box = "precise32"

  config.vm.forward_port 3000, 3000

  config.vm.share_folder "app", "/home/vagrant/app", "app"

  # allow for symlinks in the app folder
  config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/app", "1"]
  config.vm.customize ["modifyvm", :id, "--memory", 512]

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "cookbooks"
    chef.add_recipe "apt"
    chef.add_recipe "mongodb"
    chef.add_recipe "build-essential"
    chef.add_recipe "nodejs::install_from_package"
    chef.json = {
      "nodejs" =&gt; {
        "version" =&gt; "0.8.0"
        # uncomment the following line to force
        # recent versions (&gt; 0.8.4) to be built from
        # the source code
        # , "from_source" =&gt; true
      }
    }
  end
end
</code></pre>
<p>Let&#8217;s go through the config file to understand what its doing. First, we are telling Vagrant to use the base box named &#8216;precise32&#8242; you downloaded a few moments ago. Then we configure port forwarding between the Vagrant VM and our host over port 3000, and a shared folder in which we will put our application code. Then some VM hardware settings, such as RAM configuration. Finally, we configure the automation system (chef_solo, in this case), and add the recipes from our &#8216;/cookbooks&#8217; directory defining the applications and services we want to install in the Vagrant VM. Note that I can also pass in specific configurations in JSON format &#8211; I&#8217;m using this to specify the exact version of Node.js (0.8.0) I want to install.</p>
<p>To power on your custom VM, from inside your application directory issue the following command:</p>
<p><code>$ vagrant up</code></p>
<p>If this is the first time you have issued this command for a new project, Vagrant will actually create the VM from scratch, which may take a few moments. The next time you enter the command, it will just power the VM on, which is substantially faster. When the &#8216;vagrant up&#8217; command is issued, Vagrant works in the background to stand up the VM required for that environment (as defined in the Vagrantfile). If you open up the VirtualBox UI you can actually watch the VM appear, but there&#8217;s no real reason to do so &#8211; you won&#8217;t need the UI to interact with your VM. Instead, once the VM is up, type:</p>
<p><code>$ vagrant ssh</code></p>
<p>This will automatically give you an ssh session into your Vagrant VM, without the need to enter a hostname or credentials. You should see console output similar to the following:</p>
<p><a href="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-up.png"><img src="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-up.png" alt="vagrant-ssh" width="577" height="157" class="aligncenter size-full wp-image-207" /></a></p>
<p>As you can see, Vagrant has created and ssh session for me into my Vagrant VM. This is the running environment for your application. It&#8217;s a clean VM, with only a base operating system and the exact applications you configured installed. Issue the following commands to verify the installation of Node.js, NPM, and MongoDB:</p>
<p><code>$ node-v<br />
$ npm -v<br />
$ mongo -version</code></p>
<p>if you do an &#8216;ls&#8217;, you will also notice a directory &#8216;/app&#8217;, located in your vagrant home directory. Inside is your application code &#8211; these files are actually located on your host system, but are visible on your vagrant VM as a VirtualBox shared directory. This is where you will run your code. The shared directory means I can pull up Sublime Text 2 in my host OS (OSX), and edit the files that will be run in the Vagrant VM. I could start the test application now to see it running, but to get an optimal workflow, I want something that will restart my application when changes are made to the code. To get this functionality in Node.js, go ahead and install supervisor on your Vagrant VM from the ssh command line:</p>
<p><code>$ sudo npm install supervisor -g</code></p>
<p>(Note: I could eventually roll this installation into my chef recipes that set up this environment, to save myself a step)</p>
<p>Now launch the application:</p>
<p><code>$ supervisor app/app.js</code></p>
<p>Open up a text editor or IDE in your host system, and open the vagrant-node-mongo/app/app.js file for editing. Now here&#8217;s a really cool part. Open a browser in your host system, and navigate to http://localhost:3000. Since your Node.js app is running in your Vagrant VM, you will see the following:</p>
<p><a href="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-hello-world.png"><img src="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-hello-world-e1360514201913.png" alt="vagrant-hello-world" width="500" height="253" class="browser-window-image aligncenter size-full wp-image-208" /></a></p>
<p>The application is running in your Vagrant VM, but you can test it on your host browser, just as if it were running locally! Now go into your text editor and change the app.js code from</p>
<pre><code>var http = require('http');

server = http.createServer(function(req, res) {
  res.writeHead(200, {"Content-Type": "text/html"});
  res.write("&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello, World!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;");
  res.end();
}).listen(3000);
</code></pre>
<p>to</p>
<pre><code>var http = require('http');

server = http.createServer(function(req, res) {
  res.writeHead(200, {"Content-Type": "text/html"});
  res.write("&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello, from Vagrant!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;");
  res.end();
}).listen(3000);
</code></pre>
<p>Then refresh your browser window. You will see your changes reflected in the running application.</p>
<p><a href="http://codehenge.net/blog/wp-content/uploads/2013/02/hello-from-vagrant.png"><img src="http://codehenge.net/blog/wp-content/uploads/2013/02/hello-from-vagrant-e1360514820793.png" alt="hello-from-vagrant" width="500" height="315" class="browser-window-image aligncenter size-full wp-image-209" /></a></p>
<p>This is the real power of Vagrant &#8211; I can code on my local machine, using my tools, applications, IDE, etc. I can run the application on my custom, controller Vagrant VM with a few short commands, and test the app using my favorite local browsers and testing tools. I&#8221;m working in a VM, but really don&#8217;t even have to know about it. Vagrant handles all the management of the VM for me. When I&#8217;m done working, I just exit out of the Vagant ssh session:</p>
<p><code>$ exit</code></p>
<p>and tell Vagrant to power down the VM:</p>
<p><code>$ vagrant halt</code></p>
<p>Then I can move on to another project. I can have a Vagrant VM for each project I&#8217;m working on. Moreover, this is a <em>revolution</em> for team workflows. I can check my Vagrantfile and cookbooks into source control, just as I did with the github application we&#8217;ve been working on, and I can be assured that each member of my team will be developing his code against exactly the same runtime environment. What&#8217;s more, since we are using Chef to do the VM configuration, I can even use the same Chef cookbooks to configure my centralized test servers, my staging environment, or even production. If we change something in the runtime environment for the application, each developer issues a vagrant destroy command:</p>
<p><code>$ vagrant destroy</code></p>
<p>and then creates a new VM with the updated configurations. This process rarely takes more than 2 minutes, and results in a completely fresh, 100% matching environment for the entire team, across the entire project workflow.</p>
<p>I can be absolutely certain that I&#8217;ll never again hear &#8220;it works on my machine&#8221;, because I&#8217;ll know that every machine running my code is exactly the same.</p>
<p><strong>If you liked this article, help me out by sharing a 50% discount to my Node.js course here: <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge" data-text="Sign up for Learn Node.js by Example now and get 50% off!" data-via="AaronCois" data-size="large" data-hashtags="nodejs">Tweet</a> Thanks!</strong></p>
<p>You should follow me on Twitter here: <a href="https://twitter.com/AaronCois" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @AaronCois</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2013/02/automate-your-development-environment-with-vagrant/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Node.js Tutorial: Hello, World!</title>
		<link>http://codehenge.net/blog/2012/10/node-js-tutorial-hello-world/</link>
		<comments>http://codehenge.net/blog/2012/10/node-js-tutorial-hello-world/#comments</comments>
		<pubDate>Sat, 13 Oct 2012 02:48:58 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=188</guid>
		<description><![CDATA[This is the introductory screencast from my online course, <a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example">Learn Node.js by Example</a>! In this screencast, I present the basics of Node.js, and develop a small "Hello, World!" app. Enjoy!]]></description>
				<content:encoded><![CDATA[<p>This is the introductory screencast from my online course, <a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example">Learn Node.js by Example</a>! In this screencast, I present the basics of Node.js, and develop a small &#8220;Hello, World!&#8221; app. Enjoy!</p>

<p><iframe width="695" height="391" src="http://www.youtube.com/embed/H3aZ8h1gEf4?feature=oembed" frameborder="0" allowfullscreen></iframe></p>

<p><strong>Get 50% off my Node.js course <a href="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">here</a></strong></p>

<p>If you liked this article, help me out by sharing a 50% discount to my Node.js course here: <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge" data-text="Sign up for Learn Node.js by Example now and get 50% off!" data-via="AaronCois" data-size="large" data-hashtags="nodejs">Tweet</a> Thanks!</p>

<p>You should follow me on Twitter here: <a href="https://twitter.com/AaronCois" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @AaronCois</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2012/10/node-js-tutorial-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screencast: Node.js and MongoDB Using MongoJS</title>
		<link>http://codehenge.net/blog/2012/10/screencast-node-js-and-mongodb-using-mongojs/</link>
		<comments>http://codehenge.net/blog/2012/10/screencast-node-js-and-mongodb-using-mongojs/#comments</comments>
		<pubDate>Tue, 09 Oct 2012 01:55:22 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=186</guid>
		<description><![CDATA[Here is a free screencast from my online course, <a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example">Learn Node.js by Example</a>! In this screencast, I present the basics of using the MongoJS module to add MongoDB to your Node.js applications. Enjoy!]]></description>
				<content:encoded><![CDATA[<p>Here is a free screencast from my online course, <a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example">Learn Node.js by Example</a>! In this screencast, I present the basics of using the MongoJS module to add MongoDB to your Node.js applications. Enjoy!</p>

<p><iframe width="695" height="391" src="http://www.youtube.com/embed/j0mUoe8eghc?feature=oembed" frameborder="0" allowfullscreen></iframe></p>

<p><strong>Get 50% off my Node.js course <a href="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">here</a></strong></p>

<p>If you liked this article, help me out by sharing a 50% discount to my Node.js course here: <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge" data-text="Sign up for Learn Node.js by Example now and get 50% off!" data-via="AaronCois" data-size="large" data-hashtags="nodejs">Tweet</a> Thanks!</p>

<p>You should follow me on Twitter here: <a href="https://twitter.com/AaronCois" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @AaronCois</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2012/10/screencast-node-js-and-mongodb-using-mongojs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Socket.io With Express 3.x</title>
		<link>http://codehenge.net/blog/2012/08/using-socket-io-with-express-3-x/</link>
		<comments>http://codehenge.net/blog/2012/08/using-socket-io-with-express-3-x/#comments</comments>
		<pubDate>Sat, 25 Aug 2012 19:39:58 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[socketio]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=179</guid>
		<description><![CDATA[Excited about version 3.x of Express, the Node.js web framework? It has some great <a href="https://github.com/visionmedia/express/wiki/New-features-in-3.x" title="Express 3.x Features">new features</a>, and is certainly worth migrating to. Many of my apps make use of <a href="http://socket.io">Socket.io</a>, one of my favorite Node modules, and in this case, and as of now (Socket.io v9.1) the migration isn't as smooth as it could be. Until socket.io catches up with the changes to Express, here's how you can use it with Express 3.x.]]></description>
				<content:encoded><![CDATA[<p><a href="http://codehenge.net/blog/wp-content/uploads/2012/08/socketio9-e1345921380351.png"><img src="http://codehenge.net/blog/wp-content/uploads/2012/08/socketio9-e1345921380351.png" alt="" title="socketio9" width="300" height="102" class="alignleft size-full wp-image-180" /></a>Excited about version 3.x of Express, the Node.js web framework? It has some great <a href="https://github.com/visionmedia/express/wiki/New-features-in-3.x" title="Express 3.x Features">new features</a>, and is certainly worth migrating to. Many of my apps make use of <a href="http://socket.io">Socket.io</a>, one of my favorite Node modules, and in this case, and as of now (Socket.io v9.1) the migration isn&#8217;t as smooth as it could be. Until socket.io catches up with the changes to Express, here&#8217;s how you can use it with Express 3.x. 
Back in Express 2.x, you would create an express object:</p>

<pre><code>var express = require('express');
var app = express.createServer();
</code></pre>

<p>and then configure your socket.io object to listen along with the express app:</p>

<pre><code>var io = require('socket.io').listen(app);
</code></pre>

<p>then tell the express app to listen on a port:</p>

<pre><code>app.listen(8080);
</code></pre>

<p>One of the first changes in Express 3.x is that express.createServer() has been deprecated. If you try to use it, you will receive the following message when you start your app:</p>

<blockquote>
  <p>Warning: express.createServer() is deprecated, express applications no longer inherit from http.Server, please use: 
   var express = require(&#8220;express&#8221;);</p>
  
  <p>var app = express();</p>
</blockquote>

<p>Ok, no big deal, let&#8217;s just do exactly what it says:</p>

<pre><code>var express = require('express');
var app = express();
</code></pre>

<p><strong>Want to master Node.js?</strong> Try my highly-rated online course <a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example">Learn Node.js by Example</a>. <a href="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">Click here</a> to get 50% off on screencasts, interactive projects, and more!</p>

<p>However, you now have a very different object stored as &#8216;app&#8217; then you did in Express 2.x. Before, app was derived from the HTTP server object type, which is what socket.io expects to be passed in its listen() method:</p>

<pre><code>var io = require('socket.io').listen(app);
</code></pre>

<p>If you pass this new app object in, while no error will be thrown, the socket.io connections will not succeed. On launching your app, you will even get a helpful message:</p>

<blockquote>
  <p>Socket.IO&#8217;s &#96;listen()&#96; method expects an &#96;http.Server&#96; instance as its first parameter. Are you migrating from Express 2.x to 3.x?
  Which is a pretty good clue that you need to make some minor adjustments. Here&#8217;s how to fix things.</p>
</blockquote>

<p>First, create an HTTP server object from your new Express 3.x app object:</p>

<pre><code>server = http.createServer(app);
</code></pre>

<p>Now, pass this server object to socket.io instead:</p>

<pre><code>var io = require('socket.io').listen(server);
</code></pre>

<p>Finally, you will need to invoke the server object to start listening on a port, rather than the app object, since the server object is what socket.io is linked with. This will work fine, but is against the standard Express 3.x convention:</p>

<pre><code>server.listen(8080);
</code></pre>

<p>Keep an eye out, as you this is a change you will have to make for the time being, especially when adding socket.io into existing Express 3.x apps.</p>

<p>Happy Noding!</p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2012/08/using-socket-io-with-express-3-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Performance Rundown, 2012</title>
		<link>http://codehenge.net/blog/2012/08/javascript-performance-rundown-2012/</link>
		<comments>http://codehenge.net/blog/2012/08/javascript-performance-rundown-2012/#comments</comments>
		<pubDate>Sun, 05 Aug 2012 01:23:27 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=174</guid>
		<description><![CDATA[Before giving a conference talk on Node.js earlier this summer, I ran some limited JavaScript benchmark tests, since I couldn't find any recent (this year) data posted. Inspired by <a href="http://ejohn.org/blog/javascript-performance-rundown/">John Resig's performance analysis</a> a few years ago, I decided to expand on that study by updating browsers and adding more benchmark suites to get a more comprehensive view of performance. I'll be presenting results for the 5 top desktop browsers...]]></description>
				<content:encoded><![CDATA[<p></p>Before giving a conference talk on Node.js earlier this summer, I ran some limited JavaScript benchmark tests, since I couldn&#8217;t find any recent (this year) data posted. Inspired by <a href="http://ejohn.org/blog/javascript-performance-rundown/">John Resig&#8217;s performance analysis</a> a few years ago, I decided to expand on that study by updating browsers and adding more benchmark suites to get a more comprehensive view of performance. I&#8217;ll be presenting results for the 5 top desktop browsers:
<br />
<p></p>
<br />
<p></p>
<ul>
<li>Google Chrome v20.0.1132.47 (V8 Engine)
<li>Microsoft Internet Explorer v9.0.8112.16421 (Chakra Engine) 
<li>Firefox v14.0.1 (SpiderMonkey Engine) 
<li>Opera v12.00 (Carakan Engine)
<li>Safari v5.1.7 (SquirrelFish Engine)
</ul>

<p></p>Browser/engine versions are up to date at time of writing. Values reported are the mean of 10 consecutive runs with each browser. Tests were performed on a Intel Core i7 Macbook Pro with 8GB RAM, running Windows 7 Ultimate SP1.

<p></p>First, let&#8217;s check out the <a href="http://www.webkit.org/perf/sunspider/sunspider.html">SunSpider 0.9.1</a> JavaScript benchmark test:

<p></p><a href="http://codehenge.net/blog/wp-content/uploads/2012/08/sunspider-2012-08-04.png"><img src="http://codehenge.net/blog/wp-content/uploads/2012/08/sunspider-2012-08-04.png" alt="" title="sunspider-2012-08-04" width="960" height="720" class="alignleft size-full wp-image-176" /></a>
<br />
<p></p>
<br />
<p></p>Interestingly, the latest version of Microsoft&#8217;s Chakra engine slightly edged out Chrome and its V8 engine in my test. Fear not, the result is not statistically significant. However, I do have to give credit to MS. For the capabilities tested by SunSpider, Chakra currently performs as well as V8. The remaining browsers went Opera, Firefox, Safari, from best to worst. These differences, though they appear small on the graph, were statistically significant (p < 0.01).

<p></p>Moving on, I went to the <a href="http://v8.googlecode.com/svn/trunk/benchmarks/run.html">V8 JavaScript Benchmark Suite</a>. This is the suite used by Google internally to optimize and test the V8 engine, so expect V8 to perform well on this. Results:

<p></p><a href="http://codehenge.net/blog/wp-content/uploads/2012/08/v8-benchmark-2012-08-04.png"><img src="http://codehenge.net/blog/wp-content/uploads/2012/08/v8-benchmark-2012-08-04.png" alt="" title="v8-benchmark-2012-08-04" width="960" height="720" class="alignleft size-full wp-image-177" /></a>

<p></p>Chrome/V8 takes a solid lead here, with Firefox/SpiderMonkey a distant second, and everyone else trailing. 

<p></p>Finally, <a href="http://krakenbenchmark.mozilla.org/">Mozilla&#8217;s Kraken benchmark suite</a>:

<p></p><a href="http://codehenge.net/blog/wp-content/uploads/2012/08/kraken-benchmark-2012-08-04.png"><img src="http://codehenge.net/blog/wp-content/uploads/2012/08/kraken-benchmark-2012-08-04.png" alt="" title="kraken-benchmark-2012-08-04" width="960" height="720" class="alignleft size-full wp-image-175" /></a>

<p></p>Again, Chrome/V8 and Firefox/SpiderMonkey in a league of their own, with Chrome slightly ahead. Results here were statistically significant (p < 0.01) as well.

<p></p>So, for now, the V8 engine remains the champ (nothing to worry about here, Node.js users), though its nice to see an unexpected second wind from contenders like IE9 in some benchmarks. If I get time, I&#8217;ll try to add a few more benchmark suites to round this out, though I did find some reported results for <a href="http://www.flickr.com/photos/26983785@N02/7158672499/">Chrome vs Firefox on Peacekeeper</a> that maintain V8&#8242;s superiority. 


<div class="note" style="background-color:#f2f2e6;margin-top:50px;margin-bottom:50px">
<div style="padding:5px;font-family: 'Times New Roman', Times, serif;text-align:center;margin: 0px auto;font-style:oblique;font-size:30px;">Learn Node.js by Example</div>
<p style="padding:10px;font-family: 'Times New Roman', Times, serif;text-align:center;margin: 0px auto;font-size:18px;"> Take my online course featuring screencasts and sample projects!</p>
<div class="signup_button">
<a href="http://www.udemy.com/learn-nodejs-by-example/">
<h3 style="color:#ffffff">Sign up now</h3>
<p style="text-align: center">30-day money back guarantee!</p>
</a>
</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2012/08/javascript-performance-rundown-2012/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Best Resources to Learn Node.js</title>
		<link>http://codehenge.net/blog/2012/08/best-resources-to-learn-node-js/</link>
		<comments>http://codehenge.net/blog/2012/08/best-resources-to-learn-node-js/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 02:59:23 +0000</pubDate>
		<dc:creator>cacois</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=152</guid>
		<description><![CDATA[If you want to give Node.js a try, here's a list of my favorite Node tutorials, examples, and guides designed to help developers get up to speed on Node.js.]]></description>
				<content:encoded><![CDATA[<p><a href="http://codehenge.net/blog/wp-content/uploads/2012/08/nodejs.png"><img src="http://codehenge.net/blog/wp-content/uploads/2012/08/nodejs.png" alt="Node.js" title="nodejs" width="290" height="290" class="alignleft size-full wp-image-153" /></a> <br />
Node.js, a powerful JavaScript platform for building real-time, scalable applications, is gaining momentum among software developers. Node&#8217;s event-driven, non-blocking approach to I/O fits perfectly with JavaScripts excellent event model, allowing complex applications to be developed intuitively, with less code. Node is also built on Google&#8217;s V8 JavaScript engine, the superior runtime that gives the Chrome browser its blazing fast performance. Node is an up and coming technology, currently in use by powerhouses such as</p>

<p><a href="http://www.windowsazure.com/en-us/develop/nodejs/">Microsoft</a>, <a href="http://www.ebaytechblog.com/2011/11/30/announcing-ql-io/">Ebay</a>, <a href="http://blog.cloudfoundry.com/2012/05/24/cloud-foundry-supports-node-js-modules-with-npm/">VMWare</a>, and <a href="http://www.twitter.com">Twitter</a>. 
So, are you convinced? If you want to give Node.js a try, here&#8217;s a list of my favorite Node tutorials, examples, and guides designed to help developers get up to speed on Node.js.</p>

<p><br /></p>

<p><br /></p>

<ol>
<li><p><strong><a href="http://www.nodebeginner.org" title="NodeBeginner.org" target="_blank">NodeBeginner.org</a></strong> NodeBeginner is an online book by Manuel Kiessling that aims to &#8220;get you started with developing applications with Node.js, teaching you everything you need to know about &#8220;advanced&#8221; JavaScript along the way&#8221;. Filled with great explanations and a lot of Node examples, this book is a key resource to take a developer from Node.js beginner to programming useful applications. If you are anything like me, you&#8217;ll also learn a few new things about JavaScript programming while you are at it! This is one of my favorites for those just getting started.</p></li>
<li><p><strong><a href="http://www.udemy.com/learn-nodejs-by-example/" title="Learn Node.js by Example" target="_blank">Learn Node.js by Example</a></strong> This is a course I developed for Node.js beginners, hosted at at Udemy.com. The course is project-based, guiding students to learn by developing example applications. Instruction is given mainly through screencasts, with a lot of time spent in code. I&#8217;m actively developing new content for it, and subscribers get access to all new content for no extra cost, even if the course goes up in price. <strong><a href="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">Click here to get 50% off now!</a></strong></p></li>
<li><p><strong><a href="http://visionmedia.github.com/masteringnode/" title="Mastering Node" target="_blank">Mastering Node</a></strong> T.J. Holowaychuk, creater of pivotal Node.js tools such as Express and Jade, has an open source ebook called &#8220;Mastering Node&#8221; hosted at Github. The book, available in multiple formats, including html, mobl, epub, and pdf, is an excellent resource from one of the most knowledgeable Node.js programmers in the world. This is a Node guide you should definitely take a look at.</p></li>
<li><p><strong><a href="http://nodetuts.com" title="NodeTuts" target="_blank">NodeTuts.com</a></strong> Rails has Railscasts, and Node.js has NodeTuts http://nodetuts.com/. Pedro Teixeira has a large collection (30 and counting at the time of this writing!) of screencasts explaining various aspects of Node.js programming. His examples and explanations are practical, and extremely instructive. Highly recommended!</p></li>
<li><p><strong><a href="http://howtonode.org" title="HowToNode.org" target="_blank">HowToNode.org</a></strong> HowToNode is a community-supported blog created by Tim Caswell, the Node.js community manager at Cloud9 and core contributor to the Node.js open source project. The site contains a number of Node tutorials contributed by the Node.js community, on a variety of specific Node programming topics. This isn&#8217;t where I&#8217;d start to learn Node.js as a beginner, but it is an excellent resource to be exposed to interesting techniques and topics once you have a basic understanding of Node.</p></li>
</ol>

<p>Now get out there and learn to Node!</p>

<p><strong>Get 50% off my Node.js course <a href="http://www.windowsazure.com/en-us/develop/nodejs/">here</a></strong></p>

<p>If you liked this article, help me out by sharing a 50% discount to my Node.js course here: <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge" data-text="Sign up for Learn Node.js by Example now and get 50% off!" data-via="AaronCois" data-size="large" data-hashtags="nodejs">Tweet</a> Thanks!</p>

<p>You should follow me on Twitter here: <a href="https://twitter.com/AaronCois" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @AaronCois</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2012/08/best-resources-to-learn-node-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
