javascript


23
Nov 10

How to learn Node.js from Scratch

Server-side Javascript has appealed to me for quite a awhile, and while watching from the sidelines was interesting, I still never had the time to really get my feet wet and see how the language really worked. That changed after joining Joyent, of course. We’re the proud home of Node.js, and it would be wrong unforgivable if I didn’t know how to write JS.

It turns out that learning Javascript has been quite fun, and really easy. There are numerous resources on the internet for learning how to manipulate the DOM, and do ridiculous stuff with JQuery. But I’ve never been a UI person. I’m a server and network guy, through and through. It turns out, the hardest part about learning Javascript is finding decent documentation. Most of my learning experience has been through reading other peoples wacky, sometimes incomprehensible code, and then going through lists of tutorials that I wrote for myself. Breaking things seems to be the best way to learn how to write stuff. I also was able to rely on some of my brilliant co-workers who are full time software engineers.

Here’s a list of resources I found helpful, which don’t necessarily show up at the top of your Google search results.

NodeTuts

A decent list of tutorials as screencasts. They can be a little on the long side, but there are a few gems. Check out the one about learning how Sys.pump (util.pump) works. Once you understand how it works you’ll kind of be blown away at how easily you wrote something so powerful

Node.Js Documentation

The API documentation for node is extremely well written, a testament to Ryan’s Benevolent Dictator for Life mentality, which is a really good thing.

Crockford on Javascript

Douglas Crockford has a ton of really well written examples, standards, “best practices”, and videos. If you’re interested, check out “Javascript – The Good Parts” post, hosted on the Yahoo! developer network (Mirror please…)

Mozilla Developer Network Javascript Reference

I don’t know why this wasn’t the first result I found when I searched for things like “Javascript Object” or “Javascript Array”, but this is the best resource that explains what the native objects are, what methods they include, and provides some decent examples on their usage. A MUST read.

Learning Advanced Javascript

John Resig is putting together a book on the Secrets of Javascript, and it has something to do with Ninjas. But this part of the book is available for people to read today, and it’s pretty cool. After you nail down a lot of the style, prototyping, and closure stuff, be sure to check out this list of examples on advanced JS.


5
Feb 09

Why Serverside Javascript Matters

Javascript is a popular scripting language that comes embedded in most browsers. It’s usually what’s responsible for making your browsing experience as rich as it is, and for this reason we tend to categorize it in the realm of client-side development. In fact, running javascript on the server is odd enough for the phrase ‘Server-side Javascript’ to have been coined in the first place, but it isn’t exactly a new idea. Livewire, Netscape’s Enterprise Server product included server-side javascript functionality in 1996. But it hasn’t really caught on. Writing server-side code in PHP, Ruby, Python and Perl, ASP.Net and Java has been the “way we do things” and javascript remained something you messed around with once you wanted to spoil your users with a  richer experience. Before I explain server-side Javascript adoption, we need one important piece of background information.

There are economic concepts that dictate how you use services and hosting on the internet.

Do tell.

Computing is really cheap. Think about all the email that Gmail handles in a day. It’s so cheap that advertising can pay for it. But the “Network is the computer” after all, so we have to think about what it takes to get that information in and our of these clusters of cheap computing, and that’s the rub. Amazon charges $0.17/gig to get your data out of EC2, which is equivalent to almost two hours of their cheapest computing instance. This is a good scenario if the task you send to your cheap compute cluster can be defined in a very small package, and yields a relatively small result but typical web services and applications don’t work this way. The point is: Its cheaper to move the computing than it is to move the data.

So what?

This all clicked for me when I messed around with Freebases development environment, “Acre”. Acre is great. It lets you create, edit, and host your applications through a browser. Not only had I been messing around with Acre, but I’d also been toying with the idea of using Freebase as a mechanism for validating and normalizing data. The problem is asking Freebase for a bunch of information on say, “every city on the planet” is pretty expensive. Not only do you incurr a network transfer cost, but you then have to process the information. Not exactly ideal. But what if I could pose a question to an application running at Freebase? What if, instead of pulling out all the information about every movie and creating your own Freebase-based IMDB, you could host it right next to the data source. You get all the benefits of transferring the ‘heavy stuff’ over the WAN, and the browser gets the good stuff, but only when it asks for it.

This is why server-side javascript is perfect

Hosting Ruby, PHP, Python, etc is kind of a pain in the ass. Well its easier than it used to be but it could be a lot better. If I had to choose something relatively lightweight to interface to my data-source and create that rich browsing experience, you’d probably pick Javascript. My initial impression is that depending on your data-source, scaling it would be easy, too. Running computing close (as in LAN close) to the data-set means a few things

1. You can create cheaper mashups

2. You can eliminate all the cruft from your data before it gets sent over the wire

3. You can create nifty applications and ask them short questions that yield short answers but require huge amounts of data to determine

ZOMG How do I start?

You’ll have to learn javascript, and as a hosting or service operator you’ll have to choose an application for running it server-side. There are a few options. Trusty Wikipedia has a lengthy list of Server-side Javascript implementations. I’d recommend checking out the following:

Rhino

Spidermonkey

V8

AppJet

Jaxer

-Trevor