March, 2011

27
Mar 11

Nodechat.js continued – authentication, profiles, ponies, and a meaner socket.io

As promised, here is a follow up tutorial on the node.js/socket.io/backbone.js/express/connect/jade/redis stack that powers nodechat.js.

The first nodechat.js tutorial introduced some fancy ideas, like using backbone.js on the server and streaming models over socket.io which is all well and great, but it left some of the more practical questions unanswered. Issues like coordinating authentication between express/connect and socket.io and creating, storing, and retrieving user profiles, are less sexy, but still quite important for real world use. So that is what the next this tutorial will look at. Practical stuff. Besides, everything is more fun when you do it in node, right?

I will also sprinkle you with some other neat wisdom nuggets along the way. If you want.

Continue reading →

14
Mar 11

nodechat achieves glorious internet notoriety

Two weeks ago, I released a tutorial on using node.js, backbone.js, socket.io, and redis to make a simple realtime chat app. Someone posted it to Hacker News and it made it the front page. fzysqr.com enjoyed brief fame and notoriety. The number one complaint (other than my awesome user interface) was that there was no demo. So without thinking (at all) I threw the code up on a Joyent no.de (Joyent are a bunch of node-ninjas and no.de is the best thing since ponies, check them out) and posted the link on HN and on fzysqr.com. Whups.

I have learned a few things over the last couple weeks. Good “lessons” I will share with you now:

  1. Don’t actually put your crappy code online, publicly, for abuse. It will crash.
  2. Sanitize inputs for your crappy demo code before you try to run it (in violation of rule number 1). XSS attacks will significantly lessen the quality of the experience you are trying to provide your audience.
  3. Check for nulls. Everywhere. The internet is a cruel place and people are mean. They will look through your crappy demo code and figure out how to crash your crappy demo.
  4. Running production-ish code on node.js requires a different mindset. If anything takes the process down, it is down for everyone. Coming from a typical web-development background, it took much crashing before I realized this. Writing robust, fault tolerant code is CRITICAL if you are hosting it on node.js
  5. If you write a silly chat room and hang out it in all day, you will meet many interesting people.
  6. There is a ton of interest in node.js. People are really excited to work with this stack.

People seemed to enjoy nodechat.js so I have been hacking out new features as fast as I can. Things that have changed since the demo:

  • Authentication: reserve your username now, before they are all gone!
  • Rightside up chat
  • Mashtags: like #hashtags but #mashier
  • Users online: now people are more than numbers
  • Direct messages: now you can tell @jslatts how much you hate the UI in private
  • Notifications: blinky tab thingies
  • Linkify URLS / em / bold
  • Flood control (yes, that one guy who knows who he is, I am thinking of you)
  • Works in Firefox (sorry FF, I don’t test in you)
  • Still Fun Chat Messages only

As always, you can find the latest code at github.

I am working on a follow up tutorial to cover authentication and some other fun tidbits I have discovered in the last couple weeks. Stay tuned.

11
Mar 11

pgrep – Using PowerShell to fill the Windows grep void. Of pain.

I use windows at work. I hate the windows command line. I REALLY miss grep. PowerShell has Select-String which kinda/almost/sorta does grep things. Here is how you would actually use it in a grepish way:

Get-ChildItem -recurse -include *.txt | Select-String -CaseSensitive "SomeString"

Recursively searches all text files in the current directory tree for SomeString with case sensitivity.

This sucks to type. So let’s alias it to a function.

function pgrep { param([string]$search, [string]$inc) Get-ChildItem -recurse -include $inc | Select-String -CaseSensitive $search }

Now we can:

pgrep SomeStringToSearch *.txt

Then to really make it magical, add the function alias to your PowerShell Profile and you can almost dull the pain of not having proper command line tools.

07
Mar 11

Debugging in Node.js

Is as easy as:

  1. npm install node-inspector
  2. node-inspector &
  3. chrome to http://localhost:8080/debug