No blocking parallel processing in nodejs

4.21.2013

Nodejs is an incredible & fast way to handle Asynchronous IO concurrency but as a single thread solution, it will fail if your code will not return as fast as possible the control to the main loop.

But there are cases where you need to use node itself to compute some big data via super slow algorithm.

In this article you will find a series of tests I have done to better understand the available options node have to offer to solve this specific problem.

read more


A blog in nodejs - Part 2: Add RSS feed to Poet

4.9.2013

If you read my previous article, you should have now a fantastic blog in nodejs but with a little problem; You don't have feed.

Also if Google is about to shut down google reader in the next few months, feeds will remain a good practice to serve your blog posts for a while.

There are a lot of different ways to implement feed in Poet and there is some interesting activity in the Poet official github repo about it.

For this example, we are going to use a dedicated package that give us more options out of the box to serve good feed in different formats: feed.

From the package author:

Feed is a RSS 2.0 and Atom 1.0 generator for Node.js, making content syndication simple, intuitive and performant!

read more


A blog in nodejs - Part 1: Express, Poet & coffeescript

3.31.2013

This is a first part of a series of posts that were inspired by the process of building stid.me blog.

My actual blog (the one you are reading right now), is based on Express to manage basic routing, Poet that is a super-minimal blog solution for node, coffeescript for the javascript syntax, jade for html markup and stylus for css markup.

Setup your Express app

You first step is to to create a new Express app with stylus css support:

npm install -g express
express --css stylus mysuperblog
cd mysuperblog && npm install

You should have an minimal Express working app now. Let's cleanup some routes and add some basic configurations.

Change you package.json by add your real app name:

{
  "name": "mysuperblog", // You app name here
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.1.0",
    "jade": "*",
    "stylus": "*"
  }
}

read more


A blog in nodejs!!?

3.28.2013

In the last few weeks, I had a chance to tets twitter stream API for my personal and professional pourposes.

My preferred environent in the last few years was in the most cases Ruby on Rails. It helped me and/or my teams in building fast prototyped apps that scaled very well also in production and under heavy load.

But stream API are a different beast. First, I was in the need of a light, simple and optimized way to handle multiple events and spawn part of them to the web clients. This is something that could be done in Ruby too, but it meant a lot of work on server side and a totally separated javascript logic on client side.

After some googoling, nodejs was my final choice. Play with socket.io is a pleasure, and you can prototype a real time app (both server side and client side) in minutes, based on the same language (javascript) and logic.

Nice to know... so what about this blog?

My previous blog, build in wordpress (really?!) was hacked around 3 months ago. I was in the process of rebuild it in wordpress or directly in Rails... but you know... I was just falling in love with nodejs at that point and thus, I'v decided to rebuild it entirely in nodejs.

It could look like a crazy decision at start... but I was impressed by the options offered by node. You do not have all this out of the box stuff and solutions coded and tested for years, but things are evolving very fast on node as far as I have learned. There are alredy a bunch of production ready solutions around (packages) and node seems to have reached a stable level too.

To be totally honest, this was also possible because I don't want a widget overloaded blog this time. I want to keep it light and simple as I can and I love the idea to release new features as I will learn a new language and its ecosystem.

My objective is to publish a series of articles about these learning process. For now, and because I can't resist to put all this stuff in production, I leave you with this "superefficent feed generator" snippet as a super-geeek welcome message for this new blog (this could be done on a C64 via BASIC for sure... but in coffeescript and nodejs it feel far more cool, you don't think so?).

PS: As you have probably noticed, English is not my first language... but I'll try to do my best.

RSS = require("feed")

class RssFeed
    constructor: (@posts) ->
        @feed = new RSS(
            title:          'stid.me'
            description:    'This is stid personnal feed!'
            link:           'http://stid.me/'
            image:          'http://stid.me/image.png'
            copyright:      'All rights reserved 2013, Stefano Furiosi'

            author:
                name:       'Stefano Furiosi'
                email:      '########'
                link:       'https://stid.me/about'
            )

        for post in @posts
            @feed.item
                title:  post.title,
                description: post.preview,
                link: post.url
                author: 'Stefano Furiosi'
                date: post.date

    to_feed: ->
        @feed.render('rss-2.0')

module.exports = RssFeed

read more