Categories
Technology Writing

Node: References and Resources

Recovered from the Wayback Machine.

During my explorations of Node.js, I came across many excellent resources, references, tutorials, and various other online publications related to the technology. I had planned on incorporating this material into an appendix for Learning Node but decided it would make a better online resource than a book chapter.

Every person interested in Node should start with the Node.js web site, as well as the web site for npm, the application that manages Node module installations:

If you’re interested in Node in a Windows environment, you might a little extra help in getting set up. I recommend the following resources:

There’s an enormous number of resources for the Node.js newbie, including basic tutorials and entire online books. I know there are more than what I discovered, but the following is a good start:

One person, Felix Geisendörfer, has provided several excellent online resources for new and experienced Node folks:

As you learn Node, you’ll hear about the Node event loop. The following are a couple of good articles on the event loop:

REPL is the Node interactive stand alone application. REPL stands for Read-Eval-Print-Loop. Following are good REPL resources:

Modules are the heart and soul of Node.js. It can be an interesting experience finding Modules, because you need to look carefully among the many available to see which are the ones currently supported, and which have, more or less, been abandoned. Luckily, there are good Node module resources:

A good rule of thumb about which module to use is check for recent activity in the module’s repository. Are there outstanding issues? Pull requests that have gone unanswered for a long time? Also do a Google search, see who is using the module, for what, and how recently.

For more on npm, itself, do check out the Developer guide. Also spend some time understanding the differences between global and local installation of modules.

Node is based on the CommonJS model. If you want to learn more about CommonJS, I recommend Taking baby steps with Node.js–CommonJS and creating custom modules.

The heart of the module system is the package.json file. Nodejitsu provides an article and a couple of good cheat sheets related to package.json and npm:

Peter Krumin did a great series of articles on Node.js Modules you should know about. Several of my favorite are included in the list.

If you work with Node, and you write modules, chances are you’re going to become intimately involved with EventEmitter. The following are good EventEmitter resources and references:

Control flow is a big topic of interest for Node developers:

There are good frameworks for Node, but I focused on Connect/Express. I felt that Express was more Node-like, and requires less upfront time than the other frameworks. That’s not to say there weren’t challenges with Express, as it went from Express 2.x to Express 3.x and then back down to Express 2.x, but one adapts. I focused on Express 3 in the book.

Connect is the middleware layer for Express. TJ Holowaychuk provides an introduction to Connect 2 at Connect 2.0. The Express web site is at Express.com, though note that the documentation is still focused on Express 2. For the Express 2 developer, check out the Migrating from 2.x to 3.x guide. Mike Valstar writes specifically about Express error handling and 404 pages.

I grew fond of Redis when working with Node.js. The Redis site is at redis.io. Redis is nicely documented, at the site and in the Little Redis Book.

Following are other articles and links of interest, in no particular order or grouping:

Hack Sparrow article on running Express application in a production environment http://www.hacksparrow.com/running-express-js-in-production-mode.html. Charlie Robbins provides a how-to on distributing Node.js apps with Hook.io at http://blog.nodejitsu.com/distribute-nodejs-apps-with-hookio. More on the Hook.io module at http://ejeklint.github.com/2011/09/23/hook.io-for-dummies-part-1-overview/.

Rasmus Andersson wrote a Template for setting up Node.js-backed web apps on EC2 at http://rsms.me/2011/03/23/ec2-wep-app-template.html. Another writing on setting up Node on Amazon EC2 from Ben Nadel at http://www.bennadel.com/blog/2321-How-I-Got-Node-js-Running-On-A-Linux-M….

A XSS (Cross Site Scripting) Cheat Sheet can be found at http://ha.ckers.org/xss.html. Another cheat sheet, this time on SQL Injection at http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/.

Heroku provides instructions on how to create a self-signed SSL certificate at https://devcenter.heroku.com/articles/ssl-certificate-self. Another tutorial on the same subjec. at http://www.akadia.com/services/ssh_test_certificate.html.

I don’t cover backbone.js in the book, but an article on combing it with MongoDB, Mongoose, and Restify can be read at http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/.

A comparison of Redis and Cassandra http://hammerprinciple.com/databases/items/redis/cassandra. More on Apache Cassandra at http://cassandra.apache.org/. Redis is compared with Memcached at http://webdevrefinery.com/forums/topic/8221-memcached-vs-redis/. The Memcached web site is at http://memcached.org/.

Guillermo Rauch’s Use Jade Blocks, not Layouts, at http://www.devthought.com/code/use-jade-blocks-not-layouts/.

Curl is your friend when testing RESTful applications. Some helpful examples at http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/.
The Ruby on Rails routing guide applies equally well to Node: http://guides.rubyonrails.org/routing.html.

Charlie McConnell wrote an article on “How to use stream.pipe” at http://docs.nodejitsu.com/articles/advanced/streams/how-to-use-stream-pipe.

One of the better, more thorough answers I’ve seen at Stack Overflow is the answer to “What is the Difference between proxy server and reverse proxy server” at http://stackoverflow.com/questions/224664/difference-between-proxy-serve….

Guillermo Rauch wrote a multipart tweet filtering proxy, beginning with Part 1 at http://www.devthought.com/2012/01/24/filtering-tweets-for-your-favorite-….

Shravya Garlapati at LinkedIn, wrote a very helpful article, Blazing Fast node.js: 10 performance tips from LinkedIn Mobile http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performanc….

The Async module can be found at https://github.com/caolan/async. More on the creation of Async at http://caolanmcmahon.com/posts/asynchronous_code_in_node_js.

The Step module is located at https://github.com/creationix/step.
There is promise support in Node with Q at https://github.com/kriskowal/q, and deferred https://github.com/medikoo/deferred, as well as Futures https://github.com/coolaj86/futures.

Yes, you can use Node modules with client-side JavaScript with help from RequireJS at http://requirejs.org/. And you can scrape web pages using Node, jQuery, and Jsdom, with a little help from this article http://liamkaufman.com/blog/2012/03/08/scraping-web-pages-with-jquery-no….

Since Node is based on the CommonJS model, read more about CommonJS at http://www.commonjs.org/. An interesting article on Node, CommonJS, and custom modules by Jan Van Ryswyck can be found at http://elegantcode.com/2011/02/04/taking-baby-steps-with-node-js-commonj….

A Nodejitsu article on using the Process module can be found at http://docs.nodejitsu.com/articles/getting-started/the-process-module. More on Node and processes by at http://dailyjs.com/2012/03/22/unix-node-processes/.

More on TCP Socket Programming in Node.js at http://www.hacksparrow.com/tcp-socket-programming-in-node-js.html. A general article on TCP vs. UDP can be found at http://www.skullbox.net/tcpudp.php. More on UDP Networking at http://twistedmatrix.com/documents/current/core/howto/udp.html.

If you’re curious about the performance differences between using process.nextTick and setTimeout, you can view benchmark tests at https://gist.github.com/1257394.

Categories
Books Technology

Node’s the thing

I just finished my fourth chapter for my newest book for O’Reilly. I never feel a book is solid and real until the fourth chapter. By the fourth chapter, you have a book, not just an idea or outline.

My newest work is titled “Learning Node”, about Node, or Node.js for the purists among you. It’s a good fit with my other JavaScript books, and is focused on an interesting and rather fun technology.

I wasn’t sure about Node when it first came out. My very first JavaScript gig wasn’t client-side development, it was a server application for a company in Portland, Oregon. I can’t remember the name of the company, or even what the application was about (I have done a lot of contract work in the last 25 years) but I remember working with a contractor from Vietnam who is one of the nicest people I have ever worked with.

I also remember that server-side development with JavaScript died quickly, and there went another skill down the toilet. So when Node came around, I didn’t embrace it as profoundly as many people did.

In time, though, Node won me over. I like it—not in the giddy, bubbling-over-with-enthusiasm embrace I may have felt about server-side JavaScript (and Java, and EJB, and the earlier Cloud computing, and DHTML), but I like it. I think it’s useful. I think it is a very solid technology.

What won me over to Node? The fact that it’s based in JavaScript helped. I’m not going to join the effete in condemning JavaScript, because I like JavaScript. I think Dart is dead on arrival, and JavaScript is only going to get better over time. However, there’s also CoffeeScript for those who just can’t embrace JavaScript.

I like that we don’t have to worry about working with threads, that modules are the norm, and that Node doesn’t pretend to be the definitive solution for every problem. I also like the community support and how uncomplicated it is to create complicated applications. I don’t want to use “easy”, but Node doesn’t demand that the developer jump through an extraordinary number of loops to get a job done. For all the new geewhiz quality about Node, it’s a very pragmatic technology.

Node is also mature enough to last—no lost skills with it. The very fact that the creator of Node, Ryan Dahl, decided to step down as gatekeeper for Node, and his decision didn’t cause any earthquakes in the Node community, attests to the maturity of both the technology and the community.

The HTML5 community could learn a lot from the Node community in this regard.

If there’s a problem with Node is that many of the those who work with Node come from a Ruby/Rails/Extreme Programming background, and many of the concepts and explanations about Node reflect assumptions that can actually form a barrier to understanding. In some ways, Node can present itself as more complex than it really is, primarily because much of the terminology reflects a background that not everyone shares.

Another problem is that documentation is an interesting mix of the nonexistent, cryptic, and/or flippant—none of which is generally helpful. Then there’s the oddly peculiar “Node web style”, with web sites in dark gray backgrounds with pale gray writing, (or white background with pale tan/green/gray writing) where the only way you can see the text is by turning up the brightness of your monitor until your head hurts.

Still, times are a changing. Cloud9’s new new Node Manual web site is a solid start in the right direction, and I have high hopes for the official Node.js site, too.

Then there’s my book, which I’m sure you’ll want—if for no other reason in that it’s a nice break from me bitching about HTML5.

Categories
Browsers

Firefox: Continuous scrolling and continuous freezing

This morning I logged into Twitter, opened my HTML5 list, and started scrolling down the page to see what new outrage/toy/publication/conference was generating excitement today. Of course, I use “page” loosely, since Twitter uses the “continuous scrolling” technique to retrieve and display older tweets. You never actually get to the end of the page, you just keep getting more tweets.

I dislike the “continuous scrolling” technique with a passion that I usually reserve for governors who harass teenagers who tweet. Many times I have scrolled to an interesting looking tweet, which is suddenly moved out of view because of an awkwardly done “page” update that pushes the previously scrolled tweets out of view. The same happens, though not as abruptly, with Facebook and Google+—a less than clever use of technology to replace what the developers seem to think is beyond their users: to click the damn “More” link.

Worse than losing that tweet that piques my interest, though, is that lately when I’m using Firefox to scroll down the page of updates, the browser freezes up. At times, it can seem to unfreeze itself if I just patiently wait for it to deal with whatever internal upset it’s currently dealing with. Other times, I’ve had to kill the browser.

In the past few weeks, though, I’ve had Firefox freeze up to the point where I couldn’t use my Windows 7 system. I can’t bring up the task manager to kill Firefox. I don’t get any response from any key combination. The only recourse I’ve had in these circumstances is to hard boot my system.

Hard booting a system is not a good idea, and it’s one I shouldn’t have to be taking. However, when your system is frozen and your laptop fan is whirring like mad, you take desperate measures. Desperate measures that came close to losing my system today.

I hard booted up my less than one year old Toshiba laptop after a Firefox/Twitter freeze this morning, except that rather than the Windows prompt asking me if I wanted to start Windows in Safe Mode, I got the ominous message that the system could not find my hard drive. I tried again in a couple of minutes, but received the same message. Waiting a short time later, I was able to get to the Windows restore/repair dialog, and tried an automatic repair. This seemingly failed, and I was faced with having to restore my system using the Toshiba recovery program, which basically overwrites your disc with a brand new installation of Windows.

Before taking such a drastic step, I tried to restart my system one more time, and this time, success!

Right now, I’m backing up all of my writing research folders to my internet site, and various other files to external USB drives. I’m also using Google Chrome to write this, because, frankly, I’m wary of using Firefox for anything at this point.

It is not the browser company’s fault that web sites use JavaScript to create some chi-chi clever effect that taxes the browser’s resources, and that most of us don’t really need, and didn’t really ask for. However, it is the browser company’s fault when it can’t deal with whatever good or bad JavaScript it encounters. No browser should allow any JavaScript to freeze the application up so badly that it has to be forcibly closed. And no browser should ever be so badly coded that it can literally crash the OS.

The only extensions I use with Firefox are Firebug, AdBlocks, and Web Developer Toolkit. I suppose one of these three could be to blame for the freezing problem, but it’s the responsibility of the browser company to ensure that its extension environment is solid so that an extension can’t cause these kinds of serious problems.

Whatever happened to my favorite Firefox of bygone years? Whatever happened to the rock solid but still innovative browser I once depended on? In its desperation to beat out Chrome and it’s aggressively pushed schedule to release new browser versions seemingly every few weeks, Firefox has become increasingly erratic and unstable. I could live with the mouse cursor landing in the web page just below a form field when tabbing (and having to click on the field to realign), but I can’t live with the freezing and crashing.

After all these years, I’m going to have to switch to another browser. Right now, I’m typing this post using Chrome, but I’m not overfond of Chrome. It’s not a bad browser, but the same issue with Firefox also applies to Chrome: aggressive release schedules and seeming indifference to stability. (“Stability? We don’t need no stinken stability!”) Apple’s support for Safari on Windows seems tepid, at best, which leaves Microsoft IE and Opera. The newer versions of IE are actually fine products, and Opera seems to have found the right point between implementing the latest gewgaw and delivering a stable product—but dammit, I’m used to Firefox.

Categories
Photography Technology

Rent not to own

Recovered from the Wayback Machine.

I have used Photoshop for years. I tried to use GIMP and UFRaw, and these are wonderful tools, but I’m comfortable with Photoshop. I like Photoshop.

Unfortunately, when I recycled my last Apple computer, I also lost my last copy of Photoshop. It was an older version, but still had what I needed. I looked at buying a few new version of Photoshop for my Windows 7 laptop, but the price of a new copy of Photoshop is beyond my means. And I don’t steal software, that’s not my thing.

Fortuitously for me, Adobe came out with a new way of acquiring Photoshop: instead of buying the application, rent it instead.

For a fixed monthly cost, you can rent a copy of Photoshop (or other high end Adobe product). How much the cost is, is dependent for how long you rent it. If you rent the application month-to-month, the cost is higher. If you rent it annually, the cost can drop a substantial amount.

The subscription plan is not the most economical way of accessing the software. The subscription cost is more expensive than just buying the software and the upgrades. However, for those organizations (or people) who just need a license for a temporary period of time, or people like me who don’t happen to have several hundred dollars lying around for a software purchase, the subscription plan does provide another option.

I signed up for a subscription for Photoshop and once a month, Adobe takes a bite out of my bank account. Hopefully, eventually I’ll have the income to buy the software outright. Or I’ll learn to live with GIMP. For now, though, the subscription does work for me.

Adobe isn’t the only “rent not to own” game in town: Amazon is getting into the rental business with Kindle books. I discovered the option when looking at a high priced book on zoos and animal rights (high, as in $108.00), Amazon is especially touting this option for textbooks, such as Sensation and Perception, 8th Edition, which sells for $116.76, but can be rented for $43.61 (and up, depending on how long you keep the book).

This is all old hat for O’Reilly, my book publisher for the last several years. The company provides access to many (if not most) of its books through Safari Online—a subscription based book site. The difference, though, is that you can download Photoshop or a Kindle rental book to your device(s) and access them offline. As far as I know, you have to access Safari Online, well, online. You can access the books through a mobile device, but you still have to be online. So Safari Online is less a case of renting the book, and more subscribing to a service. With Amazon, you’re literally renting the book.

The concept of “rent not to own” has its advantages: you don’t have to buy something you only need for a limited time, have to have the cash upfront, or charge the cost of the products to a credit card (which you most likely won’t pay off, anyway). The cost is fixed, and you know the price (and conditions) before you sign up. If your finances are erratic, you can rent month to month. Best of all, by not charging, you’re not giving interest to the bloodsucking banks.

Categories
Specs Technology

Why read about it when you can play

Earlier today I got into a friendly discussion and debate on Twitter about a new web site called W3Fools. The site bills itself as a “W3Schools intervention”, and the purpose is to wake developers up to the fact that W3School tutorials can, and do, have errors.

The problem with a site like W3Fools, I said (using shorter words, or course, since this was Twitter), is that it focuses too much on the negative aspects of W3Schools, without providing a viable alternative.

But, they said, W3Fools does provide links to other sites that provide information on HTML, CSS, or JavaScript. And, I was also told, the reason W3Schools shows up first in search results is because of uncanny use of SEO optimization.

Hmmm.

It may be true that W3Schools makes excellent use of SEO, and it may be equally true that W3Schools commits egregious and painful errors. However, neither of these account for what W3Schools is doing right. If you don’t acknowledge what the site does well, you’re not going to make much headway into turning people off the site—no matter how many cleverly named sites you create.

For instance, one of the superior information sites recommended by W3Fools is the Mozilla Doc Center, or MDC as it is affectionately known. Now, I’m a big fan of MDC. I use it all the time, especially when I want to get a better idea of what Firefox supports. But look at the work you have to put in to learn about a new HTML5 element, such as the new HTML5 hgroup element:

  1. Go to main page
  2. Click on HTML5 link
  3. Search through the topics until you see one that’s titled “Sections and outlines in HTML5”, which you know you want because it mentions hgroup
  4. Have a neuron fire and realize that you can just click directly on hgroup
  5. Go to the hgroup page, past the disclaimer about what version of Firefox supports the element, looking for an example of usage
  6. Realize there is no example of how to use hgroup
  7. Go to the original Sections and Outlines in HTML5 link
  8. Go past some stuff about elephants, looking for example
  9. Go past some bullets about why all this new sectioning stuff is cool, looking for an example
  10. Break down and use your in-page search to find hgroup
  11. Finally find an example of how to use hgroup

As compared to W3Schools:

  1. Go to main page
  2. Click on Learn HTML5 link
  3. Click on New Elements link
  4. Start to scroll down when you realize the new elements are listed along the left side
  5. Click on hgroup
  6. Look at example

One thing W3Schools does well is provide a clean, simple to navigate interface that makes it very easy to find exactly what you need with a minimum of scrolling or searching.

Returning to our comparison between W3Schools and MDC, we then search for information on SQL. Oh, wait a sec: there isn’t anything on SQL at the Mozilla site. That’s because Mozilla is primarily a browser company and is only interested in documenting browser stuff.

So then our intrepid explorer must find another site, this one providing information on SQL. And if they want to learn more about PHP, they have to find yet another site. To learn about ASP? Another site, and so on.

What W3Schools also provides is one-stop shopping for the web developer. Once you’ve become familiar with the interface, and once the site has proved helpful, you’re more likely to return when you need additional information. Let’s face it: wouldn’t you rather use one site than dozens?

Screenshot of W3Schools page showing many of the topics

Let’s say, though, that you need information on CSS3. Well, you know that MDC covers CSS, so you return to the MDC site, and you click on the link that’s labeled “CSS”, and you look for something that says CSS3.

What do you mean there isn’t anything that says CSS3? What do you mean that transitions are CSS3—how am I, a CSS3 neophyte, supposed to know this?

Returning to W3Schools, I click the link in the main page that is labeled CSS3. Oh look, in the page that opens, there’s a sidebar link that’s labeled “CSS3 transitions”. And when I click that link, a page opens that provides an immediate example of using CSS3 transitions that I can try, as well as an easy to read a table of browser support.

Screenshot of W3Schools CSS3 transitions page

W3Schools doesn’t throw a lot of text before the examples, primarily because we learn web material best by example. Remember that an entire generation of web developers grew up with “View Source” as our primary learning tool.

But so far, I’ve only compared W3Schools to MDC. There are other useful sites that the W3Fools site approves. So I try the “Google: HTML, CSS, and JavaScript from the ground up” web page. When it opens, I click the link labeled CSS…

And I get a video about using CSS.

A video.

Remember in junior high or high school, when your science teacher would bring out the projector and you knew you were going to get a video? Do you remember that feeling that came over you? How you kind of relaxed, because you know the teacher wasn’t going to ask you any questions, and you didn’t have to write any notes, or even really pay attention?

I bet some of you even fell asleep during the video.

Videos are good for specific types of demonstrations—when something is complex, with many different steps, and the order of the steps and other factors have to be just so.

When it comes to CSS, HTML, and so many other web technologies, though, video is about the most passive and non-interactive learning experience there is. More importantly, if the video doesn’t have captioning, and most don’t, you’re also leaving part of your audience behind.

Now let’s return to the W3Schools site, this time looking at one of the CSS selector tutorials. The first thing you notice is that right below the example there’s a button, labeled “Try it Yourself”.

W3Schools screenshot showing the Try It button

Why read about it, when you can play?

One of the more annoying aspects of trying to learn about a specific HTML element, or a bit of CSS, is that you have to create an entire web page just to try it out. What W3Schools provides is that all important, absolutely essential, one button click to Try it out.

I’m not defending W3Schools. The site has played off the W3C title, though that doesn’t have a lot of meaning nowadays. More importantly, some of the material has errors and the site is resistant to correcting any of these errors, and this is unconscionable.

But you aren’t going to dent the popularity of the site without at least understanding why it is so popular. The W3Schools’ site is not popular because of SEO, and it’s not popular because of the W3 part of the name.

The W3Schools website is so popular because it is so usable.