Archive for February, 2010

I first talked about Duby back in November. The project has since evolved, there's now more features and it's more usable. I'm able to run MongoDB so I decided to share it. If you know nothing about Duby, read the README.

I first talked about Duby back in November. The project has since evolved, there’s now more features and it’s more usable. I’m able to run MongoDB so I decided to share it. If you know nothing about Duby, read the README.

When you start a new technology you may be lost. Node.js is young (1 year today) but there's already a bunch of frameworks (express seems to be the most advanced) and a lot of modules. The best way to begin is to explore the ecosystem. To do that, let's create our own Model-View-Controller stack.

NOTE: The whole example is available on GitHub and not all the code is in the article, so be sure to check it out.

Models

There's a lot of modules for databases and some of them have ORMs. We can use Redis, MongoDB, CouchDB, Tokyo Cabinet, Postgres, Sqlite 3, Riak... For this example we're going to use node-dirty which do not require any database installation. node-dirty is a fast JSON store and it's easy to use, have a look at the following code:

Views

Now we have data we will need views to display them. I've already written something about Mustache.js and for this example I'm gonna use it too but there are other modules available for templating. You can use EJS, HAML, Sass (for css only)...

To use Mustache.js, don't forget to use the one from the commonjs branch (master will not work with Node.js). There's another implementation faster and with built-in async named Mu.

Controllers

The important part here is not the controller itself because it's just a function which will be called by the router. There are some routers but the most interesting is Scylla mainly because it uses EJSGI (an async Rack-like interface for Javascript).

With Scylla we're defining the route with a string containing the HTTP verb and the pattern. Then we bind a function to it.

NOTE: I included the router stuff in the controller part because most of the code is in the controller.

Conclusion

As we've seen there are a lot of modules for each part of the MVC stack. It's kinda difficult to choose but it's mainly about what you like (which database you want to use, which templating engine you like and which is the most powerful router).

Most frameworks for Node.js are not fully agnostic (nor fully opiniated) yet so it can be a dealbreaker if you like things that ain't in a framework you want to use. If you're like this you can comment the article and write about your preferences. It will maybe ease the choice for newcomers in the Node.s world.

When you start a new technology you may be lost. Node.js is young (1 year today) but there’s already a bunch of frameworks (express seems to be the most advanced) and a lot of modules. The best way to begin is to explore the ecosystem. To do that, let’s create our own Model-View-Controller stack.

NOTE: The whole example is available on GitHub and not all the code is in the article, so be sure to check it out.

Models

There’s a lot of modules for databases and some of them have ORMs. We can use Redis, MongoDB, CouchDB, Tokyo Cabinet, Postgres, Sqlite 3, Riak… For this example we’re going to use node-dirty which do not require any database installation. node-dirty is a fast JSON store and it’s easy to use, have a look at the following code:

Views

Now we have data we will need views to display them. I’ve already written something about Mustache.js and for this example I’m gonna use it too but there are other modules available for templating. You can use EJS, HAML, Sass (for css only)…

To use Mustache.js, don’t forget to use the one from the commonjs branch (master will not work with Node.js). There’s another implementation faster and with built-in async named Mu.

Controllers

The important part here is not the controller itself because it’s just a function which will be called by the router. There are some routers but the most interesting is Scylla mainly because it uses EJSGI (an async Rack-like interface for Javascript).

With Scylla we’re defining the route with a string containing the HTTP verb and the pattern. Then we bind a function to it.

NOTE: I included the router stuff in the controller part because most of the code is in the controller.

Conclusion

As we’ve seen there are a lot of modules for each part of the MVC stack. It’s kinda difficult to choose but it’s mainly about what you like (which database you want to use, which templating engine you like and which is the most powerful router).

Most frameworks for Node.js are not fully agnostic (nor fully opiniated) yet so it can be a dealbreaker if you like things that ain’t in a framework you want to use. If you’re like this you can comment the article and write about your preferences. It will maybe ease the choice for newcomers in the Node.s world.

I have talked about it on my twitter account it's now there. Here's a small design refresh for Boldr. The HTML code has not changed it's just a new CSS. I was using HTML5 since the beginning. Meanwhile, I was not using CSS3 at all. I decided to do something and now I'm using @font-face for the titles, @font-face and rounded corners for the logo and CSS Animations for the links. There will be more details in a series of CSS3 articles I'll be writing soon.

And the browser compatibility is pretty large:

@font-face and rounded corners should be OK with the majority of the browsers (including IE6, 7 and 8).

CSS Animations should be OK with Safari/Chrome/WebKit and Firefox nightlies.

It's awesome to see that you can do a bit of CSS3 even with Internet Explorer and I will do more and more CSS3 in the next iterations.

I added Intense Debate to the articles, so if you have any suggestions or comments about the design you can tell me this here.