Tag: node.js

Impromptu logging from a socket.io connection

October 27, 2012 » Geek

I recently participated in a live streamed event that provided a “watching now” counter usin socket.io. Basically it was a super simple node.js script which incremented or decremented a variable when users joined and left the channel, and broadcasted the count to it’s subscribers. What I didn’t realize until right before the event that we might want to have a record for users on page at a given point in the broadcast. With so little time before the broadcast, I didn’t want to tinker with the server and break it, so I did the next best thing, I logged from the subscriber side.

I put up a quick PHP script on my laptop that allowed cross-domain access from the origin server and logged the incoming counter.

Then, in Chrome’s JavaScript console, I just hooked updates from socket.io into an XHR to provide the values to my PHP.

It worked like a charm, I didn’t have to mess with the server at a crucial point, and we got the data we needed.

Node Knockout – Team LazerCatz!

August 30, 2010 » Geek

This weekend I participated in Node Knockout with Jerod and Cody. It was awesome, we made a game in 48 hours (less than that of actual working time).

LazerCatz!
LazerCatz!

It was a lot of work, how much?

We had 129 total commits, 82 were mine, 35 belonged to Jerod, and 12 to Cody. That’s not 100% accurate because Cody had some git problems part way through, so I committed things for him. In those commits we had 245 file changes.

The final product had 974 total lines of code, as broken down by CLOC:

If you have a minute, give it a shot at http://www.lazercatzthegame.com/.

MongoDB + node.js On WebFaction

June 18, 2010 » Geek

Following a suggestion from Kloanor on a Hacker News article I got a WebFaction account to play around with node.js on.

tl;dr It’s not too hard to set up.

Getting Ready

All of this software will be installed in my home directory, so there are a few things we need to do. First, I created a sources directory so that I would have my hands on exact copies of the installed software in the future, as well as a clean place to unpack and build them.

Second, we need to create two custom applications for MongoDB and node.js using the WebFaction control panel.

This is pretty easy, just go to “Domains/Websites > Applications > Add New“. Now give it a name (I used mongodb_master) and select “Custom app (listening on port)” as the App Type.

Creating The Custom Application

Hit create and write down the port number it provides. Do this again for node.js. You can also take a moment to map these applications to a website and domain.

The Custom Applications

MongoDB

MongoDB is actually supported to some extent, with install instructions provided in the WebFaction Doc’s. I did this slightly different, so I’ll detail my version here.

Acquiring MongoDB

You can get MongoDB at http://www.mongodb.org/display/DOCS/Downloads. You’ll need the 32-Bit Linux version. At the time of this writing the most current stable release was 1.4.3.

Installing MongoDB

MongoDB comes pre-compiled, so installing it is as easy as unpacking and moving some directories.

Configuring MongoDB

In this case, MongoDB is configured at run time. But it will need a data directory. I chose to put this at ~/var/mongo/master/. You don’t have to do anything special, just make sure the directory exists, and is empty.

That’s it! MongoDB is installed. We’ll come back and fire it up after we get node.js installed.

Installing node.js

node.js is almost as easy as MongoDB. And while not documented anywhere, it does run just fine. The major point of contact here is a forum topic that details how to get it running. Again, I’m going to deviate a bit, but I’ll end up in roughly the same place.

Acquiring node.js

You can get node.js at http://nodejs.org/#download. It’s distributed as source, so there is nothing to pick and choose from. At the time of this writing the most current version was 0.1.98.

Easier done than said.

Installing node.js

You have to compile node.js, but this went perfectly clean for me. Just make sure you set the prefix when you configure, or you’ll have to do it all again.

Configuring node.js

Nothing to configure! It should be ready, like, right now.

Running Your New Software

Okay, everything is installed. Let’s get stuff running.

Running MongoDB

Running MongoDB should only take two options. --dbpath and --port.

Go ahead and fire it up, then shut it down with ctrl-c.

That’s great, but we can’t just stay logged in to SSH all the time. Let’s nohup it, background it and forget about it.

Now we can query it by setting the port on mongo

Running node.js

Before we can actually run node.js, we need to write a little application. In my case this will go in ~/webapps/noderegator_nodejs/app.js. Place yours wherever you set up your custom application for node.

Be sure to change the port number to the one issued to your application by WebFaction.

Now let’s fire that up and see it in the browser. ctrl-c to quit.

If you got an nginx 503 error when you tried to visit the site, check that your port numbers are set up correctly.

All Done

That’s it, that’s all you need to know. Enjoy MongoDB and node.js on WebFaction. I hope it all goes well for you.