<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Guillermo Rauch's Devthought</title>
	
	<link>http://www.devthought.com</link>
	<description />
	<lastBuildDate>Sun, 01 Apr 2012 20:51:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/devthought" /><feedburner:info uri="devthought" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Introducing codestre.am</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/7BLWCMs_QMw/</link>
		<comments>http://www.devthought.com/2012/04/01/introducing-codestre-am/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 20:50:37 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1606</guid>
		<description><![CDATA[At LearnBoost, I wrote a project that sits on the intersection between two of my passions: code and education. The basic premise is that with one command you can stream your terminal to the world, and record it as a &#8230; <a href="http://www.devthought.com/2012/04/01/introducing-codestre-am/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At LearnBoost, I wrote a project that sits on the intersection between two of my passions: code and education.</p>
<p>The basic premise is that with one command you can stream your terminal to the world, and record it as a video for later. You can make lessons interactive by streaming and chatting at the same time.</p>
<p>Check it out: <a href="http://codestre.am">http://codestre.am</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/04/01/introducing-codestre-am/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/04/01/introducing-codestre-am/</feedburner:origLink></item>
		<item>
		<title>A better console.log</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/wribJNqY7lU/</link>
		<comments>http://www.devthought.com/2012/03/26/a-better-console-log/#comments</comments>
		<pubDate>Mon, 26 Mar 2012 14:56:53 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1596</guid>
		<description><![CDATA[I just created a module named console-trace that does one very simple yet very useful thing: prepend the line number and filename to console calls. To leverage it you just need to require('console-trace') and prepend a flag: console.trace.error('Test'); console.t.log('Test'); // &#8230; <a href="http://www.devthought.com/2012/03/26/a-better-console-log/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just created a module named <a href="http://github.com/learnboost/console-trace">console-trace</a> that does one very simple yet very useful thing: prepend the line number and filename to <code>console</code> calls.</p>
<p><img style="max-width: 537px; height: 344px" src="http://f.cl.ly/items/0r3t3i0P0D1w2K242p1U/Image%202012.03.26%2011:42:35%20AM.png"></p>
<p>To leverage it you just need to <code>require('console-trace')</code> and prepend a flag:</p>
<pre class="highlight" language="javascript">
console.trace.error('Test');
console.t.log('Test'); // shorthand
</pre>
<p>You can learn about a few other options in the <a href="http://github.com/learnboost/console-trace">GitHub repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/03/26/a-better-console-log/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/03/26/a-better-console-log/</feedburner:origLink></item>
		<item>
		<title>JSConf Argentina</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/gL77ica0Zz0/</link>
		<comments>http://www.devthought.com/2012/03/17/jsconf-argentina/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 03:24:24 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1567</guid>
		<description><![CDATA[I&#8217;m very proud to announce JSConf.ar, the first of its kind in South America! Check out our website and sign up to learn when the first tickets will be on sale (follow us on Twitter as well!). We&#8217;ve confirmed a &#8230; <a href="http://www.devthought.com/2012/03/17/jsconf-argentina/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="photo-figure">
<a href="http://jsconf.com.ar"><img src="http://f.cl.ly/items/2B0b1Q1O0m45030Q0A1Q/arg.png" height="146"></a>
</div>
<p>I&#8217;m very proud to announce <code>JSConf.ar</code>, the first of its kind in South America! Check out <a href="http://jsconf.com.ar">our website</a> and sign up to learn when the first tickets will be on sale (<a href="http://twitter.com/jsconfar">follow us</a> on Twitter as well!).</p>
<p>We&#8217;ve confirmed <a href="http://www.cmd.gov.ar/cmd/el-edificio">a gorgeous venue</a> that will host our 2-day event on May 19th and 20th. Expect to not just learn from the best international and local speakers, but to take home an unforgettable experience. We are bringing all the excitement and energy from <a href="http://jsconf.com">JSConf US</a> and <a href="http://jsconf.eu">JSConf EU</a> here to Argentina.</p>
<p>I want to thank Chris Williams, Mikeal Rogers &#038; the whole JSConf gang for encouraging me and helping me take this event to my home country. On this end, none of this would have come together without <a href="http://vulsai.com">Vulsai</a>, a great local media agency who met this idea with great enthusiasm and reached out to help.</p>
<p>Nos vemos pronto!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/03/17/jsconf-argentina/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/03/17/jsconf-argentina/</feedburner:origLink></item>
		<item>
		<title>Bash as a Service</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/DyHZxdroqYs/</link>
		<comments>http://www.devthought.com/2012/03/13/bash-as-a-service/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 02:35:02 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1534</guid>
		<description><![CDATA[I rarely have the need to generate man pages for a project, but I realized they could be useful for spot(1). For those situations, the solution by TJ Holowaychuk is one curl and handy Heroku-hosted web service away: curl -s &#8230; <a href="http://www.devthought.com/2012/03/13/bash-as-a-service/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I rarely have the need to generate man pages for a project, but I realized they could be useful for <a href="http://github.com/guille/spot">spot(1)</a>. For those situations, the solution by TJ Holowaychuk is one <code>curl</code> and handy Heroku-hosted <a href="http://mantastic.herokuapp.com/">web service</a> away:</p>
<pre lang="bash" class="highlight">
curl -s -F page=@file.md http://mantastic.herokuapp.com > file.1
</pre>
<p>In my computer and slow connection at home, it took 1 second to run this task as measured by <code>time(1)</code>. Not bad for something that was already in my computer (<code>curl</code>), that prevented me from needlessly having to run the <code>easy_install</code>/<code>npm</code>/<code>gem</code>/<code>brew</code>/<code>package manager of the day</code>.</p>
<p>As a matter of fact, while installing a Python CLI utility the other day, I pressed tab to autocomplete and was met with a <em>few options</em>:</p>
<pre lang="bash" class="highlight">
∞ easy_install
 easy_install      easy_install-2.5  easy_install-2.6  easy_install-2.7
</pre>
<p>The reality is that a lot of the tools we use or <strong>could be using</strong> in our terminals could be run somewhere else, and their installation could consist in setting up an alias in your bash profile. Do you need to do syntax highlighting but don&#8217;t care for installing a bunch of things?</p>
<pre lang="bash" class="highlight">
alias pygmentize="ru pygmentize"
</pre>
<p>My suggestion here is the creation of a <code>ru</code> command (codename <code>remote unix</code>) whose job would be to provide the same interface as the original command, but execute it remotely. If you pass it <code>-h</code> to get help, it takes that to the web service and outputs its response.</p>
<p>Other examples of potentially useful cloud-run tasks include any text compilers (eg: mantastic, markdown, textile), file type conversion and manipulation (eg: <a href="http://www.coderholic.com/png2gif/">png2gif</a>, <a href="http://trimage.org/">trimage</a>), and more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/03/13/bash-as-a-service/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/03/13/bash-as-a-service/</feedburner:origLink></item>
		<item>
		<title>Chrome SPDY indicator</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/6KMpBp-ExxI/</link>
		<comments>http://www.devthought.com/2012/03/10/chrome-spdy-indicator/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 20:19:19 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1517</guid>
		<description><![CDATA[With the announcement of SPDY support by Twitter, I thought it would be cool to visualize how this extends to the rest of the web as I browse it. I developed a Chrome extension you can install to visualize SPDY &#8230; <a href="http://www.devthought.com/2012/03/10/chrome-spdy-indicator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With the announcement of <a href="http://www.webmonkey.com/2012/03/twitter-catches-the-spdy-train/">SPDY support by Twitter</a>, I thought it would be cool to visualize how this extends to the rest of the web as I browse it.</p>
<p>I developed a <a href="https://chrome.google.com/webstore/detail/mpbpobfflnpcgagjijhmgnchggcjblin">Chrome extension</a> you can install to visualize SPDY support in your address bar. Source on <a href="https://github.com/guille/chrome-spdy-indicator">Github</a>.</p>
<style>
/* credits for button css: http://hellohappy.org/css3-buttons/ */
#chrome-extension-install {
background: #E3E3E3;
border: 1px solid #BBB;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
-o-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: inset 0 0 1px 1px #f6f6f6;
-moz-box-shadow: inset 0 0 1px 1px #f6f6f6;
box-shadow: inset 0 0 1px 1px #f6f6f6;
color: #333;
font: bold 12px "helvetica neue", helvetica, arial, sans-serif;
line-height: 1;
padding: 8px 0 9px;
text-align: center;
text-shadow: 0 1px 0 white;
width: 180px;
display: block;
margin: auto;
text-decoration: none;
}
#chrome-extension-install:hover {
background: #d9d9d9;
-webkit-box-shadow: inset 0 0 1px 1px #eaeaea;
-moz-box-shadow: inset 0 0 1px 1px #eaeaea;
box-shadow: inset 0 0 1px 1px #eaeaea;
color: #222;
cursor: pointer;
}
#chrome-extension-install:active {
background: #d0d0d0;
-webkit-box-shadow: inset 0 0 1px 1px #e3e3e3;
-moz-box-shadow: inset 0 0 1px 1px #e3e3e3;
box-shadow: inset 0 0 1px 1px #e3e3e3;
color: #000;
}
</style>
<p><a href="https://chrome.google.com/webstore/detail/mpbpobfflnpcgagjijhmgnchggcjblin" id="chrome-extension-install">Install Chrome Extension</a></p>
<p><a href="https://chrome.google.com/webstore/detail/mpbpobfflnpcgagjijhmgnchggcjblin"><img src="http://f.cl.ly/items/0O0i2U0x0F0h1Y2b0d0F/screen.png" height="430"></a></p>
<p>For those who haven&#8217;t heard of <a href="http://en.wikipedia.org/wiki/SPDY">SPDY</a>, it&#8217;s a new protocol being developed by Google to transport the existing HTTP protocol more efficiently (up to 50% faster). You can read more details in the official <a href="http://www.chromium.org/spdy">Chromium page</a>.</p>
<p><span id="more-1517"></span></p>
<h3>Detecting SPDY</h3>
<p>Chrome exposes a flag called <code>wasFetchedViaSpdy</code> as part of the <code>loadTimes</code> object:</p>
<pre lang="JavaScript" class="highlight">
if (window.chrome.loadTimes().wasFetchedViaSpdy) {
  // SPDY!
}
</pre>
<p>The Chrome extension uses a background page that communicates to a content script that checks for the existence of this flag as soon as it can.</p>
<p>If the value for this is false, the plugin will display a gray icon instead:</p>
<p><img src="http://f.cl.ly/items/2E1l1m2F2I2h3w0y1t1x/screen.png" height="430"></p>
<p><b>Update:</b> version 0.2.0 was released with an option to disable the gray state, and the icon was improved. Special thanks to Ehren Kret!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/03/10/chrome-spdy-indicator/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/03/10/chrome-spdy-indicator/</feedburner:origLink></item>
		<item>
		<title>Introducing spot(1)</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/elUUjzr4EWI/</link>
		<comments>http://www.devthought.com/2012/03/04/introducing-spot/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 16:11:35 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1499</guid>
		<description><![CDATA[spot is a tiny file search utility written in Bash, meant to be fast and have very straightforward usage. For example, it considers all your arguments to be the search phrase without needing quotes: And it turns on case-sensitive search &#8230; <a href="http://www.devthought.com/2012/03/04/introducing-spot/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><code>spot</code> is a tiny file search utility written in Bash, meant to be fast and have very straightforward usage.</p>
<p>For example, it considers all your arguments to be the search phrase without needing quotes:</p>
<p><img src="https://a248.e.akamai.net/assets.github.com/img/891db913d50b87ed0f06dc260135190398fc3208/687474703a2f2f662e636c2e6c792f6974656d732f315a30363369306f334f326d3079326e305130642f496d616765253230323031322e30332e303425323031323a32363a3339253230504d2e706e67"></p>
<p>And it turns on case-sensitive search if you include an uppercase letter:</p>
<p><img src="https://a248.e.akamai.net/assets.github.com/img/7ea5448f2a680aa8580c08ad102eaea568235cd7/687474703a2f2f662e636c2e6c792f6974656d732f324e3333324630563330327831583437303432632f496d616765253230323031322e30332e303425323031323a33353a3232253230504d2e706e67"></p>
<p>The aim of the utility is to be useful and straightforward for the <em>majority</em> of searches. Hence, its options will always stay limited and the codebase brief. You&#8217;re also encouraged to fork it and modify it to your liking!</p>
<p>Go to the <a href="https://github.com/guille/spot">GitHub project page</a> for download, examples and the up-to-date project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/03/04/introducing-spot/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/03/04/introducing-spot/</feedburner:origLink></item>
		<item>
		<title>Node.JS module updates</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/1Jy1_7nSOlY/</link>
		<comments>http://www.devthought.com/2012/02/27/node-js-module-updates/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 14:23:29 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Server side]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1477</guid>
		<description><![CDATA[Socket.IO 0.9.0 Socket.IO 0.9.0 has been released, and it&#8217;s packed with bug fixes and performance/stability enhancements on both the server and client codebases. Please refer to the mailing list announcement thread for a detailed changelog. This also puts us in &#8230; <a href="http://www.devthought.com/2012/02/27/node-js-module-updates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Socket.IO 0.9.0</h3>
<p><a href="http://socket.io">Socket.IO</a> 0.9.0 has been released, and it&#8217;s packed with bug fixes and performance/stability enhancements on both the server and client codebases.</p>
<p>Please refer to the mailing list <a href="http://groups.google.com/group/socket_io/browse_thread/thread/6e759a508b231b4">announcement thread</a> for a detailed changelog.</p>
<p>This also puts us in the last sprint to Socket.IO 1.0! Stay tuned in the coming weeks for the appropriate announcement.</p>
<h3>Up 0.1.5</h3>
<p>When you use the <code>up</code> CLI for <a href="http://github.com/learnboost/up">zero-downtime HTTP reloads</a>, you can already leverage <code>--watch</code> to reload your server while developing based on configuration file changes.</p>
<p>However, sometimes things change that are not captured as easily, like configuration files, caches, environment, etc. For this, you can now press <code>ctrl + R</code> in the comfort of your terminal to trigger a quick reload.</p>
<pre lang="bash" class="highlight">
 ∞ hello-world (master) up server.js
  up-cli starting cluster with 1 workers on port 3000
  up-cli `kill -s SIGUSR2 76715` or ctrl + r to load new code
  up spawning 1 workers from master 76715
  up worker 76716 created
  up worker 76716 listening on port 60995
  up-cli ctrl + r detected - reloading
  up reloading - spawning 1 new workers
  up spawning 1 workers from master 76715
  up worker 76718 created
  up worker 76718 listening on port 60997
  up worker 76718 spawned - removing old workers
  up telling worker 76716 to exit in 500ms
  up worker 76716 exited
</pre>
<h3>WebSocket.IO 0.1.6, Distribute 0.1.4</h3>
<p>Maintenance releases for these two modules.</p>
<p>The <a href="http://github.com/learnboost/websocket.io">Node.JS websocket server</a> with support for all protocols and parsers gets a maintenance fix for 0.4. WebSocket.IO powers the upcoming Socket.IO <a href="http://github.com/learnboost/engine.io">realtime core, Engine.IO</a>.</p>
<p>Distribute 0.1.4 adds a guard to aids with the debuggability of a &#8220;double-callback&#8221; situation that can result in calling <code>next</code> twice within a middleware.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/02/27/node-js-module-updates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/02/27/node-js-module-updates/</feedburner:origLink></item>
		<item>
		<title>NPM tricks</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/bCAp9ewAMa4/</link>
		<comments>http://www.devthought.com/2012/02/17/npm-tricks/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 14:25:49 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Server side]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1444</guid>
		<description><![CDATA[I decided to put together a little list of tips and tricks related to NPM you might not know about, that come from my experience working with it daily, in both production and development. Dev dependencies Make sure packages that &#8230; <a href="http://www.devthought.com/2012/02/17/npm-tricks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="photo-figure">
<img src="http://f.cl.ly/items/2f1U2L3P0l1s0o0Y2l2X/npm2.png" width="512" height="142">
</div>
<p>I decided to put together a little list of tips and tricks related to NPM you might not know about, that come from my experience working with it daily, in both <a href="https://www.learnboost.com">production</a> and development.</p>
<p><span id="more-1444"></span></p>
<h2>Dev dependencies</h2>
<p>Make sure packages that only need to be installed while developing your module, like test frameworks, are included as <code>devDependencies</code>:</p>
<pre lang="javascript" class="highlight">
"devDependencies": {
   "module": "0.1.0"
}
</pre>
<h2>Introspecting package.json</h2>
<p>Starting with Node 0.6, since <code>require()</code> can read and parse JSON files automatically, you can leverage it to easily introspect <code>package.json</code>:</p>
<pre lang="javascript" class="highlight">
// considering the module lives in lib/module.js:
exports.version = require('../package').version;
</pre>
<p>If you want to access <code>package.json</code> for other modules, you can do it like this:</p>
<pre lang="javascript" class="highlight">
require('my-module/package').name
</pre>
<h2>Linking</h2>
<p>Sometimes you&#8217;re developing two or more modules at once, and at least one of them depends on the other. And often times, in order to be able to publish the module to NPM, you need to ensure the modules that depend on it work OK prior to publishing.</p>
<p>You can leverage <code>npm link</code> to generate a global reference to a module, and then run <code>npm link &lt;package&gt;</code><br />
to install it in other modules. Consider the following example, in which <code>moduleB</code> depends on the version of <code>moduleA</code> you&#8217;re currently developing, and <code>moduleB</code> specifies <code>"moduleA"</code> as a dependency in its <code>package.json</code></p>
<pre lang="bash" class="highlight">
$ cd moduleA/
$ npm link
$ cd ../moduleB

# if moduleB package.json is pointing to a yet-unpublished
# version of moduleA, npm install will fail:
$ npm install

# this will install your local version of moduleA
$ npm link moduleA

# since moduleA is now installed, npm install will ignore it:
$ npm install
</pre>
<h2>Production flags</h2>
<p>When deploying, you want <code>npm install</code> to be as fast as possible. To make sure NPM doesn&#8217;t waste time installing <code>devDependencies</code>, use the <code>--production</code> option:</p>
<pre lang="bash" class="highlight">
$ npm install --production
</pre>
<p>If you&#8217;re logging its output, you also want it to only output the absolutely necessary.</p>
<pre lang="bash" class="highlight">
$ npm install --loglevel warn
</pre>
<h2>Git dependencies</h2>
<p>If you haven&#8217;t published a certain package to the NPM registry, or you can&#8217;t because it&#8217;s a private module, you can point to a <code>git://</code> URI instead of a version number in your <code>package.json</code>:</p>
<pre lang="javascript" class="highlight">
"dependencies": {
    "public": "git://github.com/user/repo.git#ref"
  , "private": "git+ssh://git@github.com:user/repo.git#ref"
}
</pre>
<p>The <code>#ref</code> portion is optional, and it can be a branch (like <code>master</code>), tag (like <code>0.0.1</code>) or a partial or full commit id (thanks @Roman for pointing this out). I recommend you use git tags as references to ensure <code>npm install</code> always keeps the module up to date.</p>
<h2>Local binaries</h2>
<p>Sometimes you need to reference a <code>bin</code> from a module you depend on. It&#8217;s not uncommon to have <code>Makefile</code> tasks that leverage a certain node program to perform a compilation or run tests.</p>
<p>Make sure you avoid referencing globally installed binaries like this:</p>
<pre lang="make" class="highlight">
test:
  mocha mytest.js
</pre>
<p>Instead, point it to the local <code>node_modules</code>, which installs the binaries in a hidden <code>.bin</code> directory:</p>
<pre lang="make" class="highlight">
test:
  node_modules/.bin/mocha mytest.js
</pre>
<p>Make sure the module (in this case <code>"mocha"</code>) is in your <code>package.json</code> under <code>devDependencies</code>, so that the binary is placed there when you run <code>npm install</code>.</p>
<p>If you don&#8217;t care for <code>Makefile</code>s, you can also leverage <code>npm run-script</code> by defining the <code>scripts</code> namespace in your <code>package.json</code>:</p>
<pre class="highlight" lang="javascript">
"scripts": {
    "test": "mocha mytest.js"
  , "build": "uglify mycode.js
}
</pre>
<p>You can run them like this:</p>
<pre class="highlight" lang="javascript">
$ npm run-script test
$ npm run-script build
$ npm test # shortcut for `run-script test`
</pre>
<p>Finally, you can also leverage <code>$PATH</code> and add the relative path <code>./node_modules/.bin/</code> to your profile. Then, every time you <code>cd</code> to a module you can type in the scripts directly!</p>
<h2>Private repositories</h2>
<p>If you never intend to publish a certain module, and you want to avoid accidental publication, make sure to set <code>private</code> like this in your <code>package.json</code>:</p>
<pre lang="javascript" class="highlight">
"private": true
</pre>
<p>If you have many private repositories, you might want to consider setting up your own registry, in which case the configuration would look something like this:</p>
<pre lang="javascript" class="highlight">
"publishConfig": { "registry": "https://yourregistry:1337/" }
</pre>
<h2>Shrinkwrapping</h2>
<p>NPM has great support for <a href="http://semver.org/">semantic versioning</a> through the usage of wildcards and expressions in dependencies definitions:</p>
<pre lang="javascript" class="highlight">
"dependencies": {
    "some-module": "1.0.x"
  , "some-other-module": "<=2.0.0"
}
</pre>
<p>This, however, can lead to unexpected failure when running <code>npm install</code> over time. At one point your app might work fine, and the next time you deploy, errors can be introduced without changing anything in your code base, due to the introduction of a new version of a dependency with errors. To better understand this problem refer to <a href="http://debuggable.com/posts/npm-an-intervention:4f44dd25-a114-4361-ada1-6cefcbdd56cb">this blog post</a>.</p>
<p>The <code>shinkwrap</code> NPM command solves this situation rather elegantly. Running </p>
<pre lang="bash" class="highlight">
$ npm shrinkwrap
</pre>
<p>will generate a snapshot of the dependency graph suitable for deployments. For more information about the inner workings of this command, read <a href="http://blog.nodejs.org/2012/02/27/managing-node-js-dependencies-with-shrinkwrap/">this article</a> by Joyent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/02/17/npm-tricks/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/02/17/npm-tricks/</feedburner:origLink></item>
		<item>
		<title>Node “HTTP Hello World” showdown</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/ZKkEd-aCVeo/</link>
		<comments>http://www.devthought.com/2012/02/08/node-http-hello-world-showdown/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 11:48:50 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1396</guid>
		<description><![CDATA[Daniel Kang recently made public a partial implementation of the Node.JS API in C++11 (also known as C++0x) named node.native. #include &#60;iostream&#62; #include "http.h" using namespace native::http; int main() { http server; if(server.listen("0.0.0.0", 8080, [](request&#038; req, response&#038; res){ res.set_status(200); res.set_header("Content-Type", &#8230; <a href="http://www.devthought.com/2012/02/08/node-http-hello-world-showdown/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.daniel.gs/">Daniel Kang</a> recently made public a partial implementation of the Node.JS API in <a href="http://en.wikipedia.org/wiki/C%2B%2B11">C++11 </a>(also known as C++0x) named <a href="https://github.com/d5/node.native">node.native</a>.</p>
<pre class="highlight" lang="c++">
#include &lt;iostream&gt;
#include "http.h"
using namespace native::http;

int main()
{
    http server;
    if(server.listen("0.0.0.0", 8080, [](request&#038; req, response&#038; res){
        res.set_status(200);
        res.set_header("Content-Type", "text/plain");
        res.end("C++ FTW\n");
    })) std::cout &lt;&lt; "Server running at http://0.0.0.0:8080/" &lt;&lt; std::endl;

    return native::run();
}
</pre>
<p>Why is a C++ port of Node.JS exciting? <span id="more-1396"></span></p>
<ol>
<li>The language has seen the addition of a large number of features designed to improve the usability of the language. In particular, <a href="http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B">anonymous functions</a> are part of node.native&#8217;s &#8220;Hello World&#8221; (seen above) and used <a href="https://github.com/d5/node.native/blob/master/native/tcp.h#L56">throughout</a> <a href="https://github.com/d5/node.native/blob/master/native/handle.h#L55">the</a> <a href="https://github.com/d5/node.native/blob/master/native/fs.h#L20">codebase</a>.</li>
<li>The interoperability with the existing C/C++ library ecosystem and tooling, combined with enhanced usability make C++11 very appealing. Projects like node.native prove the additions can translate into real-world APIs that could not be as straightforward otherwise.</li>
<li>Successful companies like <a href="http://www.okcupid.com/about/technology">OKCupid</a> have written entire codebases for networked applications (Node.JS&#8217;s niche) in C++. According to its co-founder, the main reason for this decision was <a href="http://www.quora.com/OkCupid/Is-OkCupid-programmed-in-only-C">performance</a>, which we&#8217;re setting out to briefly look at for C++0x in this article.</li>
</ol>
<h2>The stage</h2>
<p>The benchmarks were run on a Macbook Air laptop running OS X 10.7.2, with a 1.8 GHZ Intel Core i7 processor and 4 GB 1333 MHZ DDR3 memory.</p>
<ul>
<li><strong>JavaScript</strong>: Node v0.6.10</li>
<li><strong>LuaJIT</strong>: Luvit v0.1.5 &#8211; LuaJIT v2.0.0-beta9</li>
<li><strong>C++</strong>: node.native-117ed2 &#8211; GCC v4.6.2</li>
</ul>
<p>The code that powers each server is found in this <a href="https://gist.github.com/8b9bd96888ed8cc0c372">gist</a>. All servers should behave in almost the exact same way. They all produce a &#8220;Hello World&#8221; 200 text/plain response.</p>
<p>The tests are run with &#8220;ab&#8221; with the following settings:</p>
<pre class="highlight" lang="bash">
 ∞ ~ ab -c 10 -n 1000 http://127.0.0.1:8080/
</pre>
<p>In order to compile node.native on OS X I installed GCC 4.6.2 separately from XCode&#8217;s, and I removed the linking to <code>librt</code> unavailable on the mac.</p>
<h2>The results</h2>
<p>The clear winner of the simple benchmark is node.native, followed by Luvit and Node.JS, being almost 40% and 80% faster respectively.</p>
<p><iframe src="http://www.devthought.com/wp-content/articles/node-lang-showdown/index.html?2" style="border: 0; height: 133px; width: 506px; background: transparent;"></iframe></p>
<p>Keep in mind this should be used as a vague reference and ongoing experiment, rather than a benchmark study to make actual decisions from. </p>
<p>It&#8217;s still interesting to see the application of libuv and the Node.JS model to other languages and the performance differences of the implementations, none of which in my opinion significant enough so far to dethrone JavaScript as the <em>one language to rule them all</em>.</p>
<p><strong>Update:</strong> following node.native&#8217;s author advice, compiling node.native with the right optimization flags has yielded a drastic performance increase! The benchmark results have been updated to reflect this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/02/08/node-http-hello-world-showdown/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/02/08/node-http-hello-world-showdown/</feedburner:origLink></item>
		<item>
		<title>Staying up with Node.JS</title>
		<link>http://feedproxy.google.com/~r/devthought/~3/2d8mW6gp7S8/</link>
		<comments>http://www.devthought.com/2012/01/29/staying-up-with-node-js/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 15:38:41 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Server side]]></category>

		<guid isPermaLink="false">http://www.devthought.com/?p=1360</guid>
		<description><![CDATA[To many beginner Node.JS users, a fundamental and immediate apparent disadvantage of writing their web applications with Node.JS lies in the inability to save a file, refresh the browser and see their changes live. This &#8220;problem&#8221; is rooted of course &#8230; <a href="http://www.devthought.com/2012/01/29/staying-up-with-node-js/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To many beginner Node.JS users, a fundamental and immediate apparent disadvantage of writing their web applications with Node.JS lies in the inability to save a file, refresh the browser and see their changes live.</p>
<p>This &#8220;problem&#8221; is rooted of course in significantly different architectures. In the case of, for example, PHP applications we traditionally separate the role of the <strong>web server</strong> and <strong>request handler</strong>. The monolithic web server maps incoming requests to the execution of particular files in the file system, which become our handlers.</p>
<p>In most setups, the web server is mostly limited to inspecting two pieces of a HTTP request: the <strong>resource</strong> (like <code>/test.php</code>) and the <strong>Host</strong> header (like <code>www.mydomain.com</code>) for <em>virtual hosts (vhosts)</em> support.</p>
<p><span id="more-1360"></span></p>
<pre class="highlight" lang="bash">
GET /test.php HTTP/1.1
Host: www.mydomain.com
</pre>
<p>With this in place, it&#8217;s up to the execution of the &#8220;test.php&#8221; file to handle the work and produce the response. If we change this file, even while other requests are ongoing, subsequent requests will be handled by our new code.</p>
<p>In Node.JS, this separation is not part of the core design. You write your web server and requests handlers as part of the same unit. This of course is the result of a tradeoff: Node.JS offers <em>complete control</em> over how the entire system operates, allowing programmability of aspects beyond the execution of a request. This includes for example, control over the <em>connections</em> that trigger the requests, easy awareness of other connections/requests, and other details that made the development of software like <a href="http://socket.io">Socket.IO</a> possible.</p>
<div class="annotations">
<div class="annotation" style="top: 40px; left: 300px;">^ The web server</div>
<div class="annotation" style="top: 140px; left: 200px;">^ The request handler</div>
<pre class="highlight" lang="javascript">
var server = require('http').createServer(onRequest);
server.listen(80);

function onRequest (req, res) {
  res.writeHead(200);
  res.end('Hello world');
});
</pre>
</div>
<p>The need for seamless code reloads extends into the realm of production deployment as well: one needs to be able to serve new requests with fresh code immediately, without breaking existing ones (such as file uploads or content transfer).</p>
<h2>The up solution</h2>
<p>Over at <a href="https://www.learnboost.com">LearnBoost</a>, we&#8217;ve solved these problems with two small projects: <a href="http://github.com/learnboost/distribute">distribute</a> and <a href="http://github.com/learnboost/up">up</a>.</p>
<p>In order to reload code without dropping requests, no changes to a codebase are needed other than ensuring that there&#8217;s a file that exports a <code>http.Server</code> as a module (let&#8217;s call it <code>server.js</code>).</p>
<pre class="highlight" lang="javascript">
  var server = require('express').createServer();
  // … code
  module.exports = server;
</pre>
<p>Then, during development you can leverage <a href="http://github.com/learnboost/up">up</a> from the CLI:</p>
<pre class="highlight" lang="bash">
$ up --watch --port 8080 server.js
</pre>
<p>The <code>--watch</code> flag will watch the working directory for changes. <code>up</code> will start workers to handle the requests, and reload them seamlessly. Alternatively, one can also do this programmatically. In the following example I listen on the <code>SIGUSR2</code> signal to trigger a reload, which allows for easy interoperability between components.</p>
<pre class="highlight" lang="javascript">
var up = require('up')
  , master = http.createServer().listen(8080)

var srv = up(master, __dirname + '/server');

process.on('SIGUSR2', function () {
  srv.reload();
});
</pre>
<h2>The power to distribute</h2>
<p>The server returned by <code>up</code> builds on top of another LearnBoost project called <a href="http://github.com/learnboost/distribute">distribute</a>, which leverages <a href="http://github.com/nodejitsu/node-http-proxy">node-http-proxy</a> by <a href="http://nodejitsu.com">NodeJitsu</a></p>
<p>The idea is simple: we can handle requests to be proxied in a middleware-style API. This allows us to solve, for example, the lack of multiple VHosts:</p>
<pre class="highlight" lang="javascript">
var httpServer = require('http').createServer()
  , srv = require('distribute')(httpServer);

httpServer.listen(80);

srv.use(function (req, res, next) {
  if ('blog.learnboost.com' == req.headers.host) {
    next(3500); // port 3500
  } else {
    next(3000); // otherwise port 3000
  }
});
</pre>
<p>And since it&#8217;s possible to re-use and chain multiple middleware functions together, it provides a proven foundation for code re-usability. In fact, it&#8217;s possible to leverage existing Express/Connect middleware like query string or cookie parsing, should a certain proxying function need it.</p>
<p>Head to <a href="http://github.com/learnboost">GitHub</a> for the projects, or find them on NPM as <code>distribute</code> and <code>up</code>. And stay tuned for an upcoming distribute middleware component release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2012/01/29/staying-up-with-node-js/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.devthought.com/2012/01/29/staying-up-with-node-js/</feedburner:origLink></item>
	</channel>
</rss>

