Node Knockout Creation: DropNode

August 29th, 2010 by James Carr

Just wraped up the weekend of participating in Node Knockout and my teams creation, DropNode is now functioning out in production letting people with bleeding edge browsers share all sorts of files and binary files with their friends and family. So i thought it’d be a good time to reflect on the experience but first talk about the app itself and what makes it cool. :)

It took a bit of brainstorming, but we decided on a simple website that lets you share files by just drag and dropping them in the browser and using the new HTML5 File API to share them. The thing that really makes it innovative is when you drag and drop a file in the browser it doesn’t just upload it for others to download, but rather generates a link on the server that when someone clicks on will cause the server to force the client (the person sharing the file) to use the File API to read the file and PUT it over XHR. The data is then relayed to the person downloading the file. So a request is what triggers an upload from the person sharing. :)

So, how’d the competition go? First off my team was made up of some really awesome devs who did a tremendously awesome job despite having little to no experience with nodejs. We did a little up front planning, but this was mostly limited to talking about how it’s going to work and doing a small spike to see if the HTML5 File API + websockets could be used to transfer files. A gotcha here is that I did the spike and succeeded with the caveat that binary files didn’t work right but decided to ignore that problem thinking we could solve it during the KO. Boy was I wrong… that wound up to be the biggest annoyance in the 11th hour. Another thing that helped was we dropped all the features into Pivotal Tracker and kept the communication channel high by using irc or pairing in person (sadly I could not pair in person).

Luckily I had deployed an app to heroku using the node.js beta so once the competition started I knew all we needed to do to get a simple hello world app deployed… create the project structure, create a package.json with our dependencies and run npm bundle ./vendo to bundle up all of our 3rd party dependencies for deployment. Within 20 minutes we were live, albeit a simple hello world app.

Development was a breeze really despite the problem we initially had with binary transfers… and it was awesome seeing the app come together and actually work. One things for sure… only once a year will I stay up till 5:45am hacking away like a madman. :)

Anyhow, go check us out at http://done-js.no.de and vote for us! :)

Well That Was Easy

August 25th, 2010 by James Carr

Spent some time working on a little app tonight and we needed to import users from one app to another. We decided we didn’t need any real fancy schmancy authentication… if the user says that their email address is foo@example.com then we’ll believe them and let them participate!

The 3rd party app had an internal url we could fetch exported email addresses from in csv format (with only one column for the addresses) so I just fetched the url, grabbed the emails and hashed each one into couchdb to authenticate against. All done in 17 lines.

Yep… that was easy. :)

Node.js STL Mailing List

August 18th, 2010 by James Carr

Just wanted to get this out there. As I mentioned previously we’re going to hold the first node.js meetup in St.Louis tomorrow night and plan to continue holding them every third Thursday of the month. I’ve created a nodejs-stl google group for it and will make announcements on future meetings plus discuss potential topics and activities there as well. This is also a good place to connect with other folks in the St.Louis area that are dabbling with node.js which is quite handy if you need someone to pair in with you on something (which I am always open for, schedule permitting).

So join the discussion! :)

Node.js Meetup This Thursday, August 19th

August 18th, 2010 by James Carr

Just a quick reminder that tomorrow night (August 19th) at 6pm will be the first ever Node.Js Meetup fo the St.Louis Area. So far we’ll have Peter Griess giving a presentation on Web Workers while I’ll give a brief introduction to npm. In addition to that we should have room for a few lightning talk is anyone else h as something they’d like to share or just some discussion about node.js in general. So whether you’ve been developing with node.js or you’re just interested in finding out what it is and learning more, come out and join us!

This month’s meetup is sponsored by Object Computing, Inc. who in addition to providing food and beverages has also lent us this month’s meeting space at their St.Louis offices at 12140 Woodcrest Executive Dr. St.Louis, MO 63141. Unfortunately punching in their address will land you at Kohl’s on google maps, so do get there take Olive Blvd. west from 270 and take a right at the second turn by Commerce Bank, the building OCI is in is the one right behind it. From the entrance, take the stairs to the second floor and take a left down the hallway to room 220.

Hope to see you there!

links for 2010-08-16

August 16th, 2010 by James Carr

links for 2010-08-14

August 14th, 2010 by James Carr

Read Only Properties in ES5

July 29th, 2010 by James Carr

I thought I’d take a quick moment to provide some examples of making object properties read only in EcmaScript 5 (and by extension node.js). There’s several ways to accomplish it, so I’ll just iterate over all the different ways.

Object.freeze

The quickest way to make all properties of an object read only is by calling Object.freeze on it. The interesting thing here is that (at least in node.js) no exception or warning will take place if you try to assign a read only property… it will appear that the assignment succeeded when in reality it didn’t.

Let’s try an object with some additional types… nested object and an array.

In this example, we see that the array and object represented by b can in fact be modified, they just can’t be reassigned to something new. It really just locks the reference. However if we loop over each property and freeze each one each will be unmodifiable and the attempt to push an element onto the array with throw an exception stating TypeError: Can't add property 4, object is not extensible.

Define Only a Getter

Another way to make a property read only is by only defining a getter for it. You can do this both via defineProperty or defineGetter

Both will throw an exception on an attempt to reassign them.

Defined as Not Writable Via Property Descriptor

One more way is to define the writable attribute in the property descriptor.

That’s just a quick overview, there’s also quite a few interesting tricks to locking object instances.

Using an SSL Certificate to Make a Secure HTTP Request in Node.JS

July 26th, 2010 by James Carr

I’m documenting this only because I had some difficulty finding info online… the API docs tell you what you need, but it took me a couple hours to get things working and a little known bug that threw my work off track.

So say you want to make a secure request to a website, perhaps a secure API call (as is most common with payment gateway APIs) and you’re using nodejs… what do you do? Assuming you already have a private key and an SSL Certificate handy and that you’ve compiled nodejs with ssl support, I’ll show you how in the following steps. :)

First, place the cert somewhere that your script can access it from, I usually prefer a location like ./certs. Make absolutely positively sure that you have no trailing newlines at the end. You also have the option of embedding it within your script (I’ve seen it done) but I believe this is a poor practice. Still, you have the option of doing that.

Given that your script/app/module is located in the same directory as the certs directory, load the contents of both keys into memory and use the crypto module to create the credentials.

With the credentials now available, we can set up the client and make a request

That is, createClient(port, host, secure, credentials). If everything goes well you should be able to make a request. One thing to watch out for is a trailing newline at the end of your key or cert. Often times I add key.replace(/\n$/, '') to it just to be safe.

Payflow Pro API released for nodejs

July 24th, 2010 by James Carr

On and off over the past couple days I’ve been working on a nodejs module to interact with Paypal’s Payflow Pro API to allow the acceptance of online payments within node.js apps. The feature list is steadily growing and soon I hope to implement the parts of the API that let paypal do the heavy lifting as well as certificate based authentication.

It’s available via npm and installation is a snap. Given that you have npm installed, just type

and bam, it’s now available for use. Here’s a quick sample to get started (this is using my existing sandbox account):

If all goes well, you should see some console output for either success or failure.

Feel free to check out the github repository, especially if you’d like to contribute.

Stay tuned… there’s more to come both from this module and more payment modules I plan to develop. ;)

Defining Getters and Setters in NodeJS

July 19th, 2010 by James Carr

Recently I discovered something interesting while messing around with NodeJS… you can define getters and setters using the ECMAScript5 syntax. For a useless example I could do something like this:

This is kind of boring though because it’s just a more complicated way of doing

however you can notice in the first example you can add any kind of custom behavior to the getter and setter and access it via person.age. Where this does become useful however is if you want to create a read only property, which you can do by just defining the getter alone:

This will print the initial age as expected, however the last line where the attempt is made to set the property will throw the exception “TypeError: Cannot set property age of #<a Person> which has only a getter.”

A small discovery, yet very useful. ;)