<?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"
	>

<channel>
	<title>Foo Hack</title>
	<atom:link href="http://foohack.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://foohack.com</link>
	<description>Isaac Schlueter on Web Development</description>
	<pubDate>Sat, 04 Aug 2012 01:53:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Intro to npm</title>
		<link>http://foohack.com/2010/08/intro-to-npm/</link>
		<comments>http://foohack.com/2010/08/intro-to-npm/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 23:27:32 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
		
		<category><![CDATA[foo]]></category>

		<guid isPermaLink="false">http://foohack.com/?p=156</guid>
		<description><![CDATA[

This was originally written for the Node Knockout blog, as part of their &#8220;Countdown to Knockout&#8221; series.



npm is a NodeJS package manager.  As its name would imply, you can use it to install node programs.  Also, if you use it in development, it makes it easier to specify and link dependencies.

Installing npm

First of <small><a href="http://foohack.com/2010/08/intro-to-npm/">...Read More</a></small>]]></description>
			<content:encoded><![CDATA[<p><aside>
<p class="small">This was originally written for <a href="http://nodeknockout.posterous.com/countdown-to-knockout-post-3-introduction-to">the Node Knockout blog</a>, as part of their &#8220;Countdown to Knockout&#8221; series.</p>
<p></aside></p>
<p><a href="http://npmjs.org/">npm</a> is a <a href="http://nodejs.org/">NodeJS</a> package manager.  As its name would imply, you can use it to install node programs.  Also, if you use it in development, it makes it easier to specify and link dependencies.</p>
<h2 id="installing_npm">Installing npm</h2>
<p>First of all, install <a href="http://nodejs.org/">NodeJS</a>.  Like so much of the NodeJS ecosystem, npm is very young, so you&#8217;ll generally have to use a very recent version of node in order to use it.  At the time of writing this, that means at least version 0.1.103.</p>
<p>To install npm in one command, you can do this:</p>
<pre><code>curl http://npmjs.org/install.sh | sh
</code></pre>
<p>Of course, if you&#8217;re more paranoid than lazy, you can also get the <a href="http://github.com/isaacs/npm">latest code</a>, check it all out, and when you&#8217;re happy there&#8217;s nothing in there to pwn your machine, issue a <code>make install</code> or <code>make dev</code>.</p>
<h2 id="what_no_sudo">what, no sudo?</h2>
<p><strong>I strongly encourage you not to do package management with sudo!</strong>  Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut.  Sure, it&#8217;s fast and definitely going to cut through any obstacles, but you might actually <em>want</em> that obstacle to stay there.</p>
<p>I recommend doing this once instead:</p>
<pre><code>sudo chown -R $USER /usr/local
</code></pre>
<p>That sets your user account as the owner of the <code>/usr/local</code> directory, so that you can just issue normal commands in there.  Then you won&#8217;t ever have to use sudo when you install node or issue npm commands.</p>
<p>It&#8217;s much better this way.  <code>/usr/local</code> is <em>supposed</em> to be the stuff you installed, after all.</p>
<h2 id="getting_help_npm_help">Getting help: <code>npm help</code></h2>
<p>npm has a lot of help documentation about all of its commands.  The <code>npm help</code> command is your best friend.  You can also tack <code>--help</code> onto any npm command to get help on that one command.</p>
<h2 id="installing_stuff_npm_install">Installing stuff: <code>npm install</code></h2>
<p>You probably got npm because you want to install stuff.  That&#8217;s what package managers do, they install stuff.</p>
<p><code>npm install blerg</code> installs the latest version of <code>blerg</code>.  You can also give <code>install</code> a tarball, a folder, or a url to a tarball.  If you run <code>npm install</code> without any arguments, it tries to install the current folder.</p>
<p>This command can do a lot of stuff.  <code>npm help install</code> will tell you more than you ever wanted to know about it.</p>
<h2 id="showing_things_npm_ls">Showing things: <code>npm ls</code></h2>
<p>The <code>npm ls</code> command shows what&#8217;s on your system, and also what&#8217;s available in the registry.  The arguments are beautifully colored greps.  For instance <code>npm ls installed</code> would show you what&#8217;s installed on your system.  <code>npm ls installed marak</code> would show you all the packages installed on your system created by <a href="http://jimbastard.com/">Marak</a>.</p>
<p><code>npm help ls</code> for more info.</p>
<h2 id="updating_packages_npm_update">Updating packages: <code>npm update</code></h2>
<p>The <code>update</code> command does a few things.</p>
<ol>
<li>Search the registry for new versions of all the packages installed.</li>
<li>If there&#8217;s a newer version, then install it.</li>
<li>Point dependent packages at the new version, if it satisfies their dependency.</li>
<li>Remove the old versions, if no other package names them as a dependency.</li>
</ol>
<p>So basically, update behaves a lot like a &#8220;standard&#8221; package manager&#8217;s update command, except that it also checks to make sure that the new version isn&#8217;t going to break anything before it points stuff at it.</p>
<p>You see, npm keeps you out of dependency hell.</p>
<h2 id="development_npm_link">Development: <code>npm link</code></h2>
<p>The link command symlinks a package folder into your system, so that changes are automatically reflected.  It also installs the <code>"dependencies"</code> and <code>"devDependencies"</code> packages from your package.json file.</p>
<p>This is one of the most useful tools for developing programs with node.  Give your thing a name and a version in a <code>package.json</code> file.  Specify a few dependencies and a <code>main</code> module.  Then run <code>npm link</code>, and go to town coding it and testing it out in the node repl.  It&#8217;s great.</p>
<p>npm is a development tool, first and foremost.  People sometimes say &#8220;Yeah, I haven&#8217;t gotten time to check out that package manager stuff yet.  Maybe I will when my code is more stable.&#8221;</p>
<p>That&#8217;s like saying that you&#8217;re going to start using source control when your code is done.  It&#8217;s just silly.  Source control should make your process <em>easier</em>, and if it doesn&#8217;t, then you&#8217;re using a broken SCM.  Same for package management.  It should make it easier, and if it doesn&#8217;t, then something is wrong.</p>
<p>npm isn&#8217;t &#8220;for&#8221; publishing.  That&#8217;s just something it can do.  It&#8217;s &#8220;for&#8221; playing.  That&#8217;s why I wrote it: to play with your code, without having to remember a dozen different ways to install your stuff, or having to get you all to structure your code the same way.</p>
<p>It&#8217;s <em>supposed</em> to make the process funner.</p>
<h2 id="making_a_package_the_packagejson_file">Making a Package: The <code>package.json</code> file.</h2>
<p>The <code>package.json</code> file goes in the root of your package.  It tells npm how your package is structured, and what to do to install it.</p>
<p>Most of the time, you only need the <code>"name"</code>, <code>"version"</code>, and <code>"main"</code> fields  (even for node-waf compiled addons).  </p>
<p>If you don&#8217;t know <a href="http://json.org/">json</a>, then it&#8217;s about time you learn it.  It&#8217;s pretty easy.</p>
<p>Use <code>npm help json</code> to learn which fields npm cares about.  Basically, it&#8217;s as simple as putting the package.json file in the root of your project, and then telling it how to get to your code.</p>
<p>Seriously.  It&#8217;s incredibly easy.  If you disagree, please <a href="mailto:i@izs.me">let me know</a>.</p>
<h2 id="acquiring_fame_npm_publish">Acquiring Fame: <code>npm publish</code></h2>
<p>So, you created a package, and you can install it.  Now you want the everlasting fame and glory that comes with other people using your code.  There is no better way to ensure your immortality than eventually being a part of every web app out there, and the best—nay, the ONLY—way to truly accomplish this is to publish nodejs packages.</p>
<p>First, create a user account with <code>npm adduser</code>.  Give it a username, password, and email address, and it&#8217;ll create an account on the npm registry.  (You can also use adduser to authorize a user account on a new machine, or fix the situation if you break your configs.)</p>
<p>Next, go to the root of your package code, and do <code>npm publish</code>.</p>
<p>Bam.  Done.</p>
<p>Now go to the mailing list and tell everyone how much more awesome they&#8217;d be if they used your program.</p>
<h2 id="dependency_hell_isn8217t_fun">Dependency Hell Isn&#8217;t Fun</h2>
<p>Most systems have a single root namespace.  That kind of sucks.  If two different things depend on different versions of the same dependency, then you&#8217;ve got two options:</p>
<ol>
<li>Statically compile the dependency into the program.</li>
<li>Hate life.</li>
</ol>
<p>Option #2 is Not Fun.  So eff that noise.  That sucks, and is dumb.</p>
<p>Option #1 is less than ideal if you want to be able to abstract out parts of your program and benefit from updates to the dependencies.</p>
<p>Thankfully, unlike most programming environments, the CommonJS Securable Module system lets you avoid dependency hell by modifying the <code>require.paths</code> at runtime, so that each package sees the version that it depends on.</p>
<p>I think that&#8217;s pretty cool.</p>
<h2 id="what_to_do_when_npm_lets_you_down">What to do when npm lets you down</h2>
<p>npm&#8217;s pretty young software, and still being actively developed.  Especially if you find yourself using some newer features, occasionally npm will have a bug.  Or, perhaps equally likely, you&#8217;ll need npm to do something that it doesn&#8217;t yet do, and want to request a feature.</p>
<p>You can post bugs and feature requests on <a href="http://github.com/isaacs/npm/issues">the issues page</a>.  If you want to ask general questions, you can ask on <a href="http://groups.google.com/group/npm-">the google group</a>.</p>
<p>Or, if you&#8217;re more the instant gratification type, you can come ask questions in IRC on <a href="irc://irc.freenode.net/#node.js">the #node.js channel on freenode.net</a>.  If I&#8217;m there, I&#8217;ll try to help you out, but this community continues to impress me with its helpfulness.  Noders rock!</p>
]]></content:encoded>
			<wfw:commentRss>http://foohack.com/2010/08/intro-to-npm/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A tech blog? How early 2000&#8217;s of you&#8230;</title>
		<link>http://foohack.com/2010/07/a-tech-blog-how-early-2000s-of-you/</link>
		<comments>http://foohack.com/2010/07/a-tech-blog-how-early-2000s-of-you/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 06:45:39 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
		
		<category><![CDATA[foo]]></category>

		<guid isPermaLink="false">http://foohack.com/?p=154</guid>
		<description><![CDATA[It occurs to me that I&#8217;ve not updated this blog at all this year.  Don&#8217;t worry, this isn&#8217;t some kind of apology post, it&#8217;s just that it occurs to me that the conversation has become increasingly less about large essay-like missives to the tech world at large, and more about targeted communication to subject-matter <small><a href="http://foohack.com/2010/07/a-tech-blog-how-early-2000s-of-you/">...Read More</a></small>]]></description>
			<content:encoded><![CDATA[<p>It occurs to me that I&#8217;ve not updated this blog at all this year.  Don&#8217;t worry, this isn&#8217;t some kind of apology post, it&#8217;s just that it occurs to me that the conversation has become increasingly less about large essay-like missives to the tech world at large, and more about targeted communication to subject-matter groups.</p>
<p>So, to recap, I&#8217;ve been maintaining <a href="http://npmjs.org/">a package manager for node.js</a>, and writing JavaScript at <a href="http://kno.com/">a company</a>, and I&#8217;m going to be writing JavaScript at <a href="http://joyent.com/">another company</a> in a month.</p>
<p>The <a href="http://nodejs.org/">NodeJS</a> community continues to impress and delight.  This is a fun group doing fun things with a fun platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://foohack.com/2010/07/a-tech-blog-how-early-2000s-of-you/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Transition</title>
		<link>http://foohack.com/2010/01/transition/</link>
		<comments>http://foohack.com/2010/01/transition/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 00:00:46 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
		
		<category><![CDATA[The Business]]></category>

		<guid isPermaLink="false">http://foohack.com/?p=146</guid>
		<description><![CDATA[My last day at Yahoo will be 2010-01-22.

Yahoo has been a mostly great company to work for, and YUI is by far the best team that I&#8217;ve worked on here.  It&#8217;s a shame that I didn&#8217;t join YUI sooner; I still feel like I just got here.  The quality of this team made <small><a href="http://foohack.com/2010/01/transition/">...Read More</a></small>]]></description>
			<content:encoded><![CDATA[<p>My last day at Yahoo will be 2010-01-22.</p>
<p>Yahoo has been a mostly great company to work for, and <a href="http://yuilibrary.com/">YUI</a> is by far the best team that I&#8217;ve worked on here.  It&#8217;s a shame that I didn&#8217;t join YUI sooner; I still feel like I just got here.  The quality of this team made the decision very difficult, and that says a lot about the job that Eric Miraglia and Thomas Sha have done building it.</p>
<p>If you ever get a chance to work at Yahoo, take it.</p>
<p>I feel so very fortunate to have met so many of Silicon Valley&#8217;s bright minds in the last 4 years, and to have learned so much about the web, about business, about people, and about the science and art of software development.  I&#8217;ve been a student, a teacher, an expert, an amateur, a mentor, and a mentee.</p>
<p>Thank you all so much for what you&#8217;ve given me.</p>
]]></content:encoded>
			<wfw:commentRss>http://foohack.com/2010/01/transition/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple Node Server</title>
		<link>http://foohack.com/2009/12/simple-node-serve/</link>
		<comments>http://foohack.com/2009/12/simple-node-serve/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 18:09:00 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://foohack.com/?p=140</guid>
		<description><![CDATA[Here is an example of a very simple lighttpd/nginx-style web server written in NodeJS.

I&#8217;ve called it simple-node-server or &#8220;sns&#8221; for short, and you can fork it on my github account.

There are a lot of folks building SSJS clones of Django and WSGI and Rack the like.  However, Python and Ruby have blocking IO, and <small><a href="http://foohack.com/2009/12/simple-node-serve/">...Read More</a></small>]]></description>
			<content:encoded><![CDATA[<p>Here is an example of a very simple lighttpd/nginx-style web server written in <a href="http://nodejs.org">NodeJS</a>.</p>
<p>I&#8217;ve called it <a href="http://github.com/isaacs/simple-node-server">simple-node-server</a> or &#8220;sns&#8221; for short, and you can <a href="http://github.com/isaacs/simple-node-server">fork it on my github account</a>.</p>
<p>There are a lot of folks building <abbr title="Server Side JavaScript">SSJS</abbr> clones of Django and WSGI and Rack the like.  However, Python and Ruby have blocking <abbr title="input/output">IO</abbr>, and even while they have the <em>capacity</em> for asynchronous behavior, it&#8217;s not the <em>default</em>.</p>
<p>I believe that, in order to get a really good JavaScript application framework, and cultivate new development in this green field, we must start with what we have, and iterate until it is closer to the ideal.  I am skeptical that we&#8217;ll be able to get there by cloning the productions of synchronicity, no matter how sophisticated they may be.</p>
<p>It is possible today to build a web server in a day, in a flexible dynamic language, which can serve an alarming number of requests per second, by embracing asynchronous architecture.</p>
<p>Let&#8217;s play: <a href="http://github.com/isaacs/simple-node-server">simple-node-server</a></p>
]]></content:encoded>
			<wfw:commentRss>http://foohack.com/2009/12/simple-node-serve/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.172 seconds -->
