Thoughts on using express.js instead of Ruby on Sinatra?

Karan Jassar picture Karan Jassar · Aug 12, 2011 · Viewed 9.3k times · Source

I'm working on a social app and considering using express.js/nodejs instead of my original choice, Sinatra/Ruby.

I'm mostly worried about the # of open source projects available in Ruby to help get things done quickly. The second major concern is the stability/maturity and completeness of express.js.

Any feedback, comments are welcome.

Answer

cbmeeks picture cbmeeks · Apr 16, 2012

Hopefully this answer will help you out. I tried to do something similar this weekend. Being a long-time supporter of Rails (and after becoming pretty good at Rails 3.2.1, I decided to jump ship this weekend and switch to Nodejs. Being an average JavaScript coder, I thought this would be fun and challenging.

I even bought a Nodejs screencast from Peepcode. So, I sit down, fire up Textmate, get a simple nodejs project going, then tweak around with Twitter Bootcamp and the app is starting to look amazing, IMHO.

Then, I get to adding database support. Then BAM. Things hit me fast. I have to find a non-blocking Postgresql driver. Fine. Found one. What? I have to manually create SQL queries? But I'm so spoiled to ActiveRecord? OK, there appears to be AR type frameworks for node. But the tutorial I was using was for Express. But wait, Nodejitsu recommended Flatiron. OK, Flatiron looks promising. But wait, I start looking at the example Flatiron uses for data management. They call it "Resourceful"? I found one example of data management about a wolf eating a squirrel? Where are the has and belongs to many examples? How do I tell Flatiron that my Notes model is polymorphic and it belongs to Trips and Expenses?

I'm sure they're out there, but I couldn't find it.

But it gets better. Shoot. I thought I hated migrations until I had to fire up pgAdmin and/or Navicat to manually create my databases. Then I had to manually create tables...oh crap. I messed up a column in pgAdmin. But it wouldn't let me change it! So I had to restart the entire table creation again. Ugh. Man, I am missing generators and rake db:migrate at this point!

Then I realized that I spent the whole weekend (well, what little time I have for coding) and all I have to show for it is an awesome static HTML page that is non-functional.

Point is, if you are good at Rails, then Nodejs is going to be a major shift. Maybe you like this? Maybe not.

At the end of the weekend, I realized something. My new app is going to be heavy on UI and is going to be sending JSON back/forth to the backend server. Rails provides an excellent toolbelt for doing this. Rails is perfectly happy speaking JSON. In fact, my app is going to be static HTML pages served via nginx and Rails will drive the data layer with controllers.

My suggestion is learn Express/Nodejs if you want to start from scratch on every piece of the development process. If you want to build your own query strings. If you want do everything manually. Maybe you like that. Maybe you have ideas on making it easier for the world. Maybe you want to use Tower.js or Flatiron.js or some other Nodejs framework.

Or, maybe you are like me and you have a damn app you want to finish. Then use Rails.