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
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
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
Writing

When last we spoke

When last I posted, I had planned on updating that post with W3C co-chair decisions on my other HTML5 issues. I wasn’t quite expecting to be here, over a month later, still waiting on decisions. Not sure what’s happening with the W3C HTML WG at the moment, other than I think the group is making like an iceberg.

Eventually the decisions will be posted. Since I have a good idea what the decisions will be, no need to continue waiting.

Other than watching pots boil, I’ve been slowly working on my first self-publishing book on HTML5. I say slowly, because I ended up drastically changing the focus of the book, and hence the table of contents.

Though I would love nothing more than to fill 150 pages with details about the various HTML5 exploits, in the end I felt that an exposé on HTML5 isn’t going to be all that useful. Cathartic, maybe, but not useful. On the other hand, I refuse to jump on the “Isn’t HTML5 just peachy keen!” bandwagon, either.

I had to find a delicate balance between HTML5 rant and HTML5 rah-rah. Once found, I then had to dig for actual HTML5 implementation experience, which is a lot more difficult than you would think, given the fooflah about HTML5.

I’m still wrestling with the new TOC, so I don’t have any early peeks, yet. One thing the book won’t have is a discussion about HTML5 the brand. For one, isn’t it time to let the Geolocation folks have a little of the spotlight, all on their own? For another, there’s been enough confusion about HTML5 without conflating a formally defined and delimited specification, with a marketing buzzword.

So in the book, I’ll talk about HTML5…and Web 5.0, and Ajax5, not to mention P2P5, as well as Cloud #5, and throw in a little DHTML5, for good measure.