Check If a Website Can Be Embedded in an IFrame with Node.js

I’ve been working on a new project recently that requires previewing external web pages in an iframe. This feature is not always possible though because websites can prevent themselves from showing in iframes by setting the x-frame-options header. Since there is no way to get around this rule, the only option is to detect whether the website sets this rule and show the user something else. The following snippet shows how to check this header from Node.

How to Scrape a Web Page with Node.js

Even though web APIs are becoming more common, it is still common to find a service you want to get data from but can’t because the data is not easily accessible. Web scraping is a last-resort technique that requires programatically extracting the required data from a webpage’s raw HTML. This tutorial will cover how to download and traverse a web page server-side using Node.js and the Zepto.js library. What we’re Building Currently, Google does not offer an API to search and browse Android applications.

Generalize Routes in Express Using Closures

If you’ve ever built a website using Node.js and Express then you’ve probably had to do something similar to the following snippet: ////////////////////// // ROUTE DEFINITIONS app.get('/', routes.index); app.get('/landing', routes.landing); app.get('/signin', routes.signin); app.get('/join', routes.join); ////////////////////////////////////// // MULTIPLE FUNCTIONS IN ROUTES FILE exports.index = function(req, res) { res.render('index'); } exports.landing = function(req, res) { res.render('landing'); } exports.signin = function(req, res) { res.render('signin'); } exports.join = function(req, res) { res.render('join'); } So what’s wrong with this code?

Get Module Version in Node.js

Here’s how to extract the version number from your package.json file. I use this to quickly verify that my current Nodejitsu snapshot is up to date. // Require package.json like a regular module var packageInfo = require('./package.json'); // Do something with the version console.log('VERSION: ' + packageInfo.version); Happy coding.

How ForkJoy Implemented AJAX Page Loads

This article will provide a fairly high level overview of how ForkJoy implemented its AJAX page loading system. ForkJoy uses Node.js and Express for its backend, Jade for templating, and JQuery on the frontend. Disclaimer The sample code used in this article is based on the ForkJoy codebase, but is heavily simplified to reduce complexity. The purpose of the sample code is not to provide a working demo, but to provide a starting point for implementation and help the readers’ understanding.

Restarting Workers in a Nodejs Cluster

We upgraded ForkJoy to Node.js v0.8 and decided to use the newly rewritten Cluster module. Cluster allows a parent Node process to manage multiple worker processes on a single port to better take advantage of multi-core machines. Before this change, Forkjoy was using Forever to restart the main process if it died. When using Cluster, Forever does not know about the worker processes (only the parent process) and therefore will not restart workers if they fail.