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

Learning Node: Raw

Evidently, O’Reilly is going to publish my Learning Node book as a Rough Cuts/Early Release.

What people should know is that the material has not gone through a final edit, a copy edit, or a tech review. So yes, there will be typos, gotchas, and oopsies. Probably lots and lots of oopsies. But the advantage to getting a Rough Cut is you get the work early, but still get the finished product when it’s complete.

I decided not to have an Appendix with all the links. This kind of material doesn’t really suit a book; it’s more appropriate for a web page. I’m in the process of converting this rich material into an online source page, which I’ll post at Tech at Burningbird when finished.

I’ll also publish a “lessons learned” from the book. Bottom line, though, is that I like Node. I think it really fills a need. What I love most about Node are child processes. I had a lot of fun with these during the book’s development. I’m definitely fond of child processes—that, and how easy it is to install and incorporate modules. The whole infrastructure just cuts through so much server-side cruft. I don’t like server-side cruft. There’s a reason I’m not a C or C++ developer.

I’ve also become a real fan girl of Redis. We have needed a Redis for years. I’m also more amenable to web sockets now, especially since the security issues have been addressed.

Categories
Just Shelley

Suggests for a smart phone

I’m finally leaving my cave and buying a real, live smart phone.

I left the Apple world over a year ago, so I’m looking at buying an Android phone. I want one that comes with Ice Cream Sandwich. Hopefully a phone that doesn’t get stuck with one version of an OS for years and years.

Any suggestions for a phone? Any suggestions for a carrier/plan, here in the US? Anything I should be wary of?

Categories
Writing

Learning Node: Well, one Rails aside

Recovered from the Wayback Machine.

After denouncing the use of Ruby and Rails terms to describe Node and Node modules, I must now confess that I did use a Rails resource in the section on MVC in Chapter 6.

The Rails Guide has an absolutely beautifully written overview on MVC and routing, Rails Routing from the Outside In, I used as inspiration for the design of the MVC section in Chapter 6.

However, in my defense I’ll note that most of this overview really doesn’t depend on knowing either Ruby or Rails in order to benefit from the writing. It simply and easily demonstrates a mapping between HTTP verbs, routes, controller actions, and database CRUD (Create-Read-Update-Delete) probably better than anything else I’ve ever read.

Categories
Writing

Learning Node: Concepts and TOC

Recovered from the Wayback Machine.

The Learning Node book is far enough along so that I can publish the Table of Contents for the book and it shouldn’t differ significantly from the TOC for the book when it’s finished. The chapters with an expanded TOC are those already finished—the rest are still in work. Before I print out the TOC, though, I thought I’d write about some of the underlying themes that helped define the book structure and determine the direction of the writing.

The primary theme behind the book is simple: you don’t have to have prior experience working with Ruby or Rails in order to understand this book.

Seems like a silly thing to say when we’re talking about a technology based in JavaScript, but you’d be amazed at how much a Ruby/Rails background assumption flavors interactions in the Node world. One of the real issues I found with Node in the last year is that all too often explanations are given in Ruby or Rail terms. For instance, when a person asked about what framework to use, another answered him that “Express is like Sinatra, while Geddy is more like Rails”. Well, that’s just peachy…if you’ve worked with Ruby, Sinatra, or Rails. If you haven’t then the answer might as well be Martian for all the useful information it provided.

My book assumes you have experience with client-side JavaScript, and you’ve mainly worked with more traditional web/Ajax type of development. There are no references to unknown technologies, and no esoteric Rubyesque or Python asides. Even when I cover how to create an MVC (Model-View-Controller) application using a popular framework, Express, I do it in such a way that you can follow along no matter how much experience you’ve had with MVC.

This doesn’t mean I talk down to my readers, but I happen to believe that Node is actually a lot easier to use than may be first apparent, and one major roadblock to understanding are all the assumptions shared among many of the current practitioners.

Another underlying theme to the book is dealing with a second major roadblock to Node adoption: lack of documentation. Or I should say, uneven documentation. Some of the third-pary modules are nicely documented, others have no documentation, and the Node modules, themselves, fit somewhere in-between. There are tutorials and other reference material—some very good material, in fact— but it’s scattered about and you have to hunt for most of it.

Having said this, the one thing the Node modules all seem to share is really nicely written code. They all seem to make excellent use of white space, good variable naming conventions, and effective use of in-line comments. The objects aren’t bizarrely defined, the coding isn’t excessively cryptic, the methods aren’t overlong, and the purpose of most can be deduced without too much trouble. Once you have a good grounding in how Node works, you can discover what you need to know about how a module works just by looking at the source.

Of course, it would still be nice if Node module developers provided a little more documentation.

(I won’t even get into the odd fascination with light gray text on darker gray backgrounds that seems to be shared by so many Node developers. Pure headache inducing web design.)

The third underlying theme in the book is to focus on providing the tools so that you can build the awesome applications—not try to create awesome applications in the book to impress you with how great I am. My examples are focused, they’re simple, they’re clean, and they show how things work. That’s it. When I want to learn how to do something, I want simple, clear examples that demonstrate exactly what I need—no more, no less. I don’t want fancy and I don’t want something overly complex. I assume most folks feel the same way, and write accordingly.

I’m also not especially creative in my writing—I try to avoid the cutesy, and definitely stay away from the profound. I’m writing a book on computer technology, not Gone with the Node.

I don’t know if all of this leaves you more interested or less, but best to set expectations right from the beginning.

My editor, Simon St. Laurent, has mentioned about the possibility of releasing my book under the Early Release and/or Rough Cuts program. I hesitate doing so, because I’ve seen reviewers who have been extremely critical of a book primarily because it is Early Release and/or a Rough Cut. Seems to me that the early release programs are equivalent to firewalking: may be great when it works, but the consequences when it doesn’t can be unfortunate.

Stay tuned on this one. If I do release early, the book will probably be available in May; otherwise, July.

Now, on with the TOC:

    • Chapter 1: Node.js, Up and Running
      • Setting up a Node Development Environment
        • Installing Node on Linux
        • Partnering Node with WebMatrix on Windows 7
        • Updating Node
      • Node: Jumping In
        • Hello, World in Node
        • Hello World, from the Top
      • Asynchronous Functions and the Node Event Loop
        • Reading a File Asynchronously
        • A Closer Look at Asynchronous Program Flow
      • Summary: Why We Like Node
    • Chapter 2: Interactive Node with REPL
      • REPL: First Looks and Undefined Expressions
      • REPL’s Own Unique Hello World
      • Multiline and More Complex JavaScript
        • REPL Commands
        • REPL and rlwrap
        • Creating Your Own REPL
      • Stuff Happens. Save Often.
    • Chapter 3: The Node Core
      • Globals: Global, Process, and Buffer
        • Global
        • Process
        • Buffer
      • The Timers: setTimeout, setInterval, clearTimeout, setInterval, and clearInterval
      • Servers, Streams, and Sockets
        • TCP Sockets and Servers
        • HTTP
        • UDP/Datagram Socket
        • Streams, Pipes, and Readline
      • Child Processes
        • child_process.spawn
        • child_process.exec and child_process.execFile
        • child_process.fork
        • Running a Child Process Application in Windows>/li>
      • Domain Resolution and URL Processing
      • Utilities and a JavaScript OO Refresher
      • Events and EventEmitter
    • Chapter 4: The Node Module System
      • Loading a Module with Require and Default Paths
      • External Modules and the Node Package Manager
      • Finding Modules
        • The Colors Module: Simple is Best
        • Optimist: Another Short and Simple
        • Exploring JSDOM
        • Underscore
      • Creating Your Own Custom Module
        • Packaging an Entire Directory
        • Preparing Your Module for Publication
        • Publishing the Module
    • Chapter 5: Control Flow, Asynchronous Patterns, and Exception Handling
      • Promises, No Promises, Callbacks Instead
      • Sequential Functionality, Nested Callbacks, and Exception Handling
      • Asynchronous Patterns and Control Flow Modules
        • Step
        • Async
      • Speaking of Node Style
    • Chapter 6: Routing Traffic, Serving Files, and Middleware
      • Building a Simple Static File Server from Scratch
      • Middleware
        • Connect Basics
        • The Connect Middleware
          • connect.static
          • connect.logger
          • connect.parseCookie and connect.cookieSession<.li>
        • Creating a Connect Middleware
      • Routers
      • Proxies
    • Chapter 7: The Express Framework
      • Express: Up and Running
      • The app.js File in More Detail
      • Error Handling
      • A Closer Look at the Express/Connect Handshake
      • Routing
        • Routing Path
        • Routing and HTTP Verbs
      • Cue the MVC
    • Chapter 8: Express, Template Systems, and CSS
      • The Embedded JavaScript (EJS) Template System
        • The Basic Syntax
        • Using EJS with Node
        • Using the EJS for Node Filters
      • Using a Template System (EJS) with Express
        • Restructuring for a Multiple Object Environment
        • Routing to Static Files
        • Processing a New Object Post
        • Widgets Index and Generating a Picklist
        • Showing an Individual Object and Confirming an Object Deletion
        • Providing an Update Form and Processing a PUT Request
      • The Jade Template System
        • The Quick Nickel Tour of the Jade Syntax
        • The Use of Block and Extend to Modularize the View Templates
        • Converting the Widget Views into Jade Templates
      • Incorporating Stylus for Simplified CSS
    • Chapter 9: Structured Data with Node + Redis
      • Getting Started with Node + Redis
      • Building a Game Leaderboard
      • Creating a Message Queue
      • Adding a Stats Middleware to an Express Application
    • Chapter 10: Storing Content with MongoDB
    • Chapter 11: The Node Relational Database Bindings
    • Chapter 12: Graphics, Video, and Audio

(Notes: Creating, streaming Canvas, Working with Imagemagic, Working with image files, multipart upload with progress, livestreaming-js. How connect.static implements ranges, allowing functionality for HTML5 video to work. Discuss ranges.)

    • Chapter 13: Creating a Quick Chat with Sockets.io

(Notes: No, not everyone needs to implement a chat client, but it is the best way to demo websockets, Speaking of which, explain websockets. (socket.io does not have session info))

    • Chapter 14: Testing and Debugging Node Applications
    • Chapter 15: Security (chapter title TBD)

(Notes: connect-auth, EveryAuth, OAuth, crypto, SSL, injection attacks, hardening code, Validating (node-validator), Sandbox (vm))

    • Chapter 16: Scaling and Deploying Node Applications

Using gearman for parallel machine deployment? Benchmarking, Deploying app to one of the clouds, Possibly Azure if I can get to work, Heroku, Joyent, others, Creating and landing a module, nodemon, hook.io?)

  • Appendix A: Git and Github
  • Appendix B: Useful Resources and References
  • Appendix C: A Redis Primer