<?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>Mon, 06 Jan 2014 03:58:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.4.1</generator>
	<item>
		<title>What is Node.js?</title>
		<link>http://codehenge.net/blog/2014/01/what-is-node-js/</link>
		<comments>http://codehenge.net/blog/2014/01/what-is-node-js/#comments</comments>
		<pubDate>Mon, 06 Jan 2014 03:58:31 +0000</pubDate>
		<dc:creator><![CDATA[cacois]]></dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[software-development]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=234</guid>
		<description><![CDATA[Node.js - It's new, its exciting...but what, exactly, is it? Let's start at the beginning...]]></description>
				<content:encoded><![CDATA[<p>Node.js &#8211; It&#8217;s new, its exciting&#8230;but what, exactly, is it?</p>
<p>You may have heard of Node.js, but know only that it has something to do with “real-time” or “highly scalable” apps. You may have heard that Node.js is JavaScript for the server-side (and you may be wondering why anyone would want that!). Or maybe you know exactly what Node.js is, but aren’t sure when or why to use it. Just sit back, and I’ll explain everything.</p>
<p>Let&#8217;s start at the beginning&#8230;</p>
<h2>The Web is Changing</h2>
<p>The web used to be about consumption. Viewing web pages, watching videos, looking at pictures of cats. Of course, its still about pictures of cats…but the web has increasingly become about interaction. Users around the world want to interact with each other, and they want to do it in real time. Chat, gaming, constant social media updates, collaboration – each of these features requires real-time communication between users, clients, and servers across the web. What’s more, this real-time communication needs to happen at massive scale, supporting hundreds, thousands, even millions of users.</p>
<p>So what do software developers need to make this happen? We need real-time communication between clients and servers – which means we need fast, persistent I/O. Anyone with web development experience knows that HTTP wasn’t built with this use case in mind. Large numbers of clients continuously polling a server simultaneously is incredibly slow and inefficient. To enable scalable real-time communication, servers need to be able to push data to clients, instead of HTTP’s heavy request/response model. We also need to make sure that these lightweight push communications work in a way that is scalable, maintainable, and usable from a software development standpoint.</p>
<h2>Enter Node.js</h2>
<p>Node.js is an event-driven, server-side JavaScript environment. Node runs JavaScript using the V8 engine developed by Google for use in their Chrome web browser. Leveraging V8 allows Node to provide a server-side runtime environment that compiles and executes JavaScript Really FastTM. The major speed increase is due to the fact that V8 compiles JavaScript into native machine code, instead of interpreting it or executing it as bytecode. Node.js and the V8 engine are both open source and cross-platform, running on Mac OSX, Windows, and Linux.</p>
<p>But JavaScript? On the server-side? Why? Though JavaScript has traditionally been relegated to menial tasks in the web browser, it’s actually a fully-functional programming language, capable of anything that more traditional languages like C++. Ruby, or Java, are. Furthermore, JavaScript has the advantage of an excellent event model, ideal for asynchronous programming. JavaScript is also a ubiquitous language, well known by millions of developers. This lowers the learning curve of Node.js, since most devs won’t have to learn a new language to start building Node.js apps.</p>
<p><a href="https://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">For a limited time, subscribe to Learn Node.js by Example now and get 50% off!</a></p>
<h2>Asynchronous Programming The Easy Way</h2>
<p>In addition to lightning fast JavaScript execution, the real magic behind Node.js is something called the Event Loop. To scale to large volumes of clients, all I/O intensive operations in Node.js are performed asynchronously. The traditional threaded approach to asynchronous code is cumbersome and creates a non-trivial memory footprint for large numbers of clients (each client spawns a thread, each thread uses dedicated memory, the memory usage adds up). To avoid this inefficiency, as well as the known difficulty of programming threaded applications, Node.js maintains an event loop which manages all asynchronous operations for you. When a Node application needs to perform a blocking operation (I/O operations, heavy computation, etc) it sends an asynchronous task to the event loop, along with a callback function, and then continues to execute the rest of its program. The event loop keeps track of the asynchronous operation, and executes the given callback when it completes, returning it’s results to the application. This allows you to manage a large number of operations, such as client connections or computations, letting the event loop efficiently managing the thread pool and optimize task execution. Of course, leaving this responsibility to the event loop makes life particularly easy for Node.js developers, who can then focus on their application functionality.</p>
<div id="attachment_236" style="width: 610px" class="wp-caption aligncenter"><a href="http://codehenge.net/blog/wp-content/uploads/2014/01/node-event-loop.png"><img src="http://codehenge.net/blog/wp-content/uploads/2014/01/node-event-loop-e1388980560411.png" alt="The Node.js Event Loop Lifecycle" width="600" height="449" class="size-full wp-image-236" /></a><p class="wp-caption-text">The Node.js Event Loop Lifecycle</p></div>
<p>This capability to simplify asynchronous programming is what makes Node.js such a powerful tool for developers. With Node.js, you can build complex applications that can scale to millions of client connections because the application handling client requests is passing off all of the time-intensive work of managing I/O and computation to the event loop.</p>
<h2>The Node.js Community</h2>
<p>In addition to it’s innate capabilities, Node.js has a thriving open source community which has produced many excellent modules to add additional capabilities to Node.js applications. One of the most famous is Socket.io, a module to manage persistent connections between client and server, enabling the server to push real-time updates to clients. Socket.io abstracts the technology used to maintain these connections away from the developer, automatically using the best technology available for a particular client (websockets if the browser supports it, JSONP or Ajax longpolling if not). This amazing technology allows you to program real-time applications simply, with very little code. For example, take this highly-scalable, real-time chat server:</p>
<pre><code>server = require('http').createServer();
server.listen(8080);

var io = require('socket.io').listen(server);
io.sockets.on('connection', function(socket){

    // when message received, send it to all connected clients
    socket.on('message', function(message){
        console.log("Received message: " + message + 
                    " - from client " + socket.id);
        io.sockets.emit('chat', socket.id, message);
    });    
});
</code></pre>
<p>Just 10 lines of code! The accompanying client-side code is just as simple. Imagine the possibilities!</p>
<p>Get started writing Node.js applications now with Learn Node.js By Example. Through detailed screencasts, tutorials, and in-depth coding exercises, this highly-rated course will have you writing Node.js applications in no time.</p>
<p><a href="https://www.udemy.com/learn-nodejs-by-example/?couponCode=codehenge">For a limited time, subscribe to Learn Node.js by Example now and get 50% off!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2014/01/what-is-node-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Discount for Online JavaScript Conference 2013</title>
		<link>http://codehenge.net/blog/2013/09/discount-for-online-javascript-conference-2013/</link>
		<comments>http://codehenge.net/blog/2013/09/discount-for-online-javascript-conference-2013/#respond</comments>
		<pubDate>Fri, 27 Sep 2013 13:44:25 +0000</pubDate>
		<dc:creator><![CDATA[cacois]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://codehenge.net/blog/?p=228</guid>
		<description><![CDATA[I’ll be speaking at the Environments for Humans JavaScript Summit on November 21st. The conference is a 3-day, all online conference, which means no travel hassle/cost, and you get to watch great talks from the comfort of home! It&#8217;s shaping up to be a great lineup (check out the list of talks!), and your registration]]></description>
				<content:encoded><![CDATA[<p>I’ll be speaking at the Environments for Humans JavaScript Summit on November 21st. The conference is a 3-day, all online conference, which means no travel hassle/cost, and you get to watch great talks from the comfort of home!</p>
<p>It&#8217;s shaping up to be a great lineup (check out the <a href="http://environmentsforhumans.com/2013/javascript-summit/">list of talks!</a>), and your registration includes copies of slides and access to recordings of talks after the event.</p>
<p>The organizers have given me a discount code to share with you: Use 20COIS to get 20% off individual or meeting room tickets. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://codehenge.net/blog/2013/09/discount-for-online-javascript-conference-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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><![CDATA[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[<div id="attachment_203" style="width: 210px" class="wp-caption alignleft"><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>
<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" style="width: 530px" class="wp-caption aligncenter"><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&#8221;. 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&#8217; 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" srcset="http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-up-96x26.png 96w, http://codehenge.net/blog/wp-content/uploads/2013/02/vagrant-up.png 577w" sizes="(max-width: 577px) 100vw, 577px" /></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>14</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/#respond</comments>
		<pubDate>Sat, 13 Oct 2012 02:48:58 +0000</pubDate>
		<dc:creator><![CDATA[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">Follow @aaroncois</a><br />
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script></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><![CDATA[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>3</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><![CDATA[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.<br />
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:<br />
   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?<br />
  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>8</slash:comments>
		</item>
	</channel>
</rss>
