Encosia - ASP.NET, AJAX, jQuery, and more

The five minute contact form tweak that saves me hours

ASP.NET, Express.js, JavaScript, Node.js By . Updated March 19, 2014

Operating a website used by predominantly non-technical users can be an eye-opening experience when the time comes to support those users. It’s easy to forget how much of the nomenclature and technical understanding that we take for granted is just unintelligible jargon to others. In fact about 10% of people surveyed this year even guessed that HTML was an STD.

A particularly poignant example I dealt with recently was a user telling me they were using “Google” to browse the Internet on their desktop PC. You’d think that probably means they were using Google Chrome as their browser, right? Nope. They were using Internet Explorer with Google’s website set as their home page.

Unfortunately, assisting the most helpless users with technical issues still requires that they communicate details about their platform and browser to you at least semi-accurately. The broader problem is bigger than anyone can solve in a thousand words, but in this post I want to show you one small improvement I’ve made on my public-facing contact forms to help cut down on confusion with this specific aspect of helping non-technical users.
Click here to read the rest of this post »

Using nConf and Azure to avoid leaking secrets on GitHub

Azure, Node.js By . Posted February 26, 2013

GitHub recently released a new version of its search feature. Unfortunately, it quickly became obvious that the feature could be misused to locate data that wasn’t intended to be exposed publicly. Passwords, oAuth tokens, and private API keys are particularly common in source code, and well-crafted searches to find them were making the social media rounds almost immediately after the new feature was released.

Of course, this sort of thing is nothing new. Similar Google searches have been possible for years. However, GitHub currently seems to house a concentration of particularly sensitive secrets. Maybe that’s because it’s so easy to accidentally commit these things along with associated code with a quick git commit -a.

I’ve been working on a few Node.js projects hosted on Windows Azure lately, and one in particular is stored in a public GitHub repository but needs access to private oAuth keys. So, this topic is something I’ve been dealing with myself lately. Through that project, I’ve been fortunate enough to stumble onto a nice symbiosis between Azure and a Node.js module called nConf that solves the problem of storing secrets in my public repositories.
Click here to read the rest of this post »

Cheerio: A faster, Windows-friendly alternative to jsdom

jQuery, Node.js By . Posted May 23, 2012

When it comes to extracting data from an HTML document on the server-side, Node.js is a fantastic option. Not so much because of any particular feature of Node itself, but because running JavaScript on the server also means that you can run jQuery on the server. Then, many of the techniques you’ve learned on the client-side are applicable on the server-side as well.

Typically, using jQuery on the server with Node is accomplished via a handy module called jsdom. Unfortunately, later versions of jsdom took a dependency on a module called contextify, and that choice has made jsdom not-so-friendly to those of us running Node.exe on Windows.

As I was jumping through the hoops to build contextify in Visual Studio, copy that binary back into my Node.exe project, and cross my fingers, I realized that maybe I’d become too fixated on jsdom as the only solution to this problem. After all, one of Node’s strengths is its thriving ecosystem of third-party libraries (reminiscent of the community that sprang up around jQuery itself several years ago).

Surely, there’s a Windows-friendly alternative to jsdom out there, right?

In this post, I’ll show you why jQuery on the server is useful, the alternative to jsdom that I found (Cheerio), and how to use Cheerio’s jQuery syntax to request and parse a remote HTML document.

Note: You don’t need to be a Windows user to benefit from Cheerio. Though jsdom impressively emulates how a browser might interpret an HTML document, at a much deeper level than most simple HTML parsers, that’s massive overkill in a lot of scenarios. In those simpler situations, jsdom carries a needless performance tax for that highly realistic simulation of the DOM.
Click here to read the rest of this post »

Learn from my Express.js HTTP status code blunder

Express.js, JavaScript, Node.js By . Posted November 9, 2011

Screenshot of the 200 Object] HTTP status code in Firebug

If you’re like me, HTTP status code 200 Object] unknown probably doesn’t ring any bells. Of course, that’s mainly because it doesn’t exist.

So, how did I end up with the screenshot above? I’ve been running with scissors again. It was one of the more popular web frameworks for Node.js that I cut myself with this time: Express.js

Unfortunately, a malformed status code like 200 Object] will cause some browsers (including the version of Chrome I was using at the time) to refuse loading the page at all. That quickly elevated the importance of my strange status code from a trivial oddity to an annoying thorn in the side.

As it turns out, my code was running up against a documented Express feature and the remedy was simple enough.

Click here to read the rest of this post »

Resolving an iisnode “The service is unavailable” 503 error

JavaScript, Node.js By . Posted October 5, 2011

I’ve been experimenting with Tomasz Janczuk’s awesome iisnode project lately, in hopes of hosting some of my Node.js sites on IIS. Those sites are running well enough on an Ubuntu VPS currently, but the features that iisnode offers are compelling (and I have unused capacity on one of my Windows servers).

Along the way, I ran into one issue that isn’t addressed in the current iisnode documentation or examples very well. If you try to set up a standalone Node.js website in IIS you’re likely to be greeted with this error when you load it up for the first time:

iisnode 503 error screen

Remotely, you’ll see the dreaded “The service is unavailable.” error:

Those nondescript errors don’t exactly make resolving the problem very straightforward. So, I want to recap what I found to be the underlying problem in my case and a few solutions, in hopes of helping anyone else that ends up with the same issue.

Click here to read the rest of this post »