20
Jun 11

Version 0.0.9 of Stalker for node.js is available

I have just released 0.0.9 of Stalker. Improvements (some from 0.0.7 as well) are:

  • Added batch mode to group callbacks
  • Added second callback for file removal notices (this works in batch mode as well)
  • Switched unit tests to vows.js and added additional coverage
  • Made errors callback immediately in standard node-fashion.
  • Fixed bugs

Get it on npm now or head to github.

Thank you for all the feedback.

08
Jun 11

Introducing stalker, a node.js module. Now your files can get restraining orders against you too.

I released my first node.js module today on npm, aptly named stalker. stalker is basically a wrapper around fs.watchFile(). It will watch a directory tree for new files and fire off your callback whenever it finds one. It tries to be smart about entire nested folder/file structures and tricksy add/removal/add type of stuff.

Get it on npm: npm install stalker

You can test it by running node example/test.js and then dropping files and folders in the example directory.

To incorporate it in your program, simply call stalker.watch with your callback:

stalker.watch('/var/foo', function(err, file) {
  console.log('stalker saw file %s', file);
});

Code is at github: https://github.com/jslatts/stalker

29
May 11

node-inspector and the missing –start-brk option

Quick tip to anyone having trouble finding the right way to start a node-inspector debugging session with an initial break point. Lot’s of youtubes and how-to’s mention a –start-brk=file.js option. If you try and actually use it, it doesn’t work. The correct way to do this now is:

node-inspector &
node --debug-brk --debug server.js 

Head to http://0.0.0.0:8080/debug?port=5858 to find your app nicely stopped on the first line.

Happy noding!

21
May 11

Kilnauth Plugin for Mercurial on a Mac

Do you use Kiln from FogCreek? Do you use a Mac? Are you having trouble getting the kilnauth plugin to work on your Mac? If so, you probably have a bad hgcookies file. To fix:

  1. Find a colleague with Windows who has a properly functioning kiln client (or follow the process in this kiln stackexchange post).
  2. Have them open up their user profile and look for an _hgookies folder. Open the cookie file inside.
  3. There will be a line that looks something like (DBID’s have been changed to protect the innocent): servername FALSE / FALSE DBID o1sev3t3dn01dabdppin90wexczimb
  4. Have them send you the DBID value
  5. On your Mac, open the cookie in your ~/.hgcookies/ and add the missing DBID value.
  6. You might have to hg logout, then try an hg get/in to put your credentials in. After that it should stop prompting you.
16
May 11

Impress your friends with client side updates

Of the many life lessons I have learned creating nodechat.js, one of the most poignant was that people like to leave their browsers (and tabs) open for a long time. This should not have been a surprise to me–I often have tabs open for weeks in the vain hope that I will get back to whatever I was doing on that page someday. This phenomena meant that users would log into nodechat, click away to another tab (or restart their browser, or suspend their PC), only to revist the nodechat tab later and find that the chat appeared frozen. The same issue occured everytime I pushed a new server update: all clients would be cut off until the user refreshed the page. Clearly this was a subpar user exeperience. This is how I fixed it.

Continue reading →

11
Apr 11

Sending your clients to purgatory (a node.js/socket.io tutorial)

Updated As has been pointed out, sending the username and password hash over to the client is not the most secure thing you can do. I wholeheartedly agree. Please do not do this on anything for real-ish. Treat this tutorial as a simple demo of how to isolate a connection until you give it some sort of approval. A much better approach would be to use a one-time throw away key or create a salted hash using the incoming client’s IP address. Or probably a million other things. The concept of isolating a connection to socket.io within a closure still applies.

Now back to your regularly scheduled programming:

One of the problems I have had with nodechat.js is that using sessions to handle the transition of authenticated users between express and socket.io has always been somewhat finicky.

Nodechat.js and the previous nodechat-tutorials have used sessions to manage this transition by storing a username and password in the session after initial login and making it available to the socket.io listener on new connections and during each message. While adequate most of the time, this method never worked correctly with all the various socket.io transports and it seemed like clients would frequently get stuck when reconnecting, requiring them to reload the page to get back into nodechat.js.

I now have a pretty decent way to address this issue and I am going to share it with you. A little technique I came up with that I call Purgatory…

Continue reading →

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