Foreword - Express.js Guide: The Comprehensive Book on Express.js (2014)

Express.js Guide: The Comprehensive Book on Express.js (2014)


Dear reader,

You are reading a book which will lead you to the understanding and fluent use of the Express.js framework — the de facto standard in web application programming on Node.js. I would especially recommend this book because it was written by a practicing engineer, who has comprehensive knowledge of the full stack of web application development, and Express.js in particular.

Azat and I worked on the same Node.js/Express.js code base at Storify — the social media curation tool that The Washington Post, CNN, BBC, The White House press corps and other news corps use. It was recently acquired by LiveFyre. Right before the Express.js Guide’s release, Azat asked me to write the foreword, because it will sound objective, sincere and unbiased coming from the creator of another Node.js framework: CompoundJS.

However, nobody is reading forewords. So, instead of a foreword, I’ll share my story. Actually, I never thought it was worth sharing and there’s definitely nothing exciting about it. But from the other point of view — thousands of young programmers living similar ordinary lives - it could be inspiring: it’s a common story, but a kind of successful one.

My path to web development started when I was a student. I’d joined a team as a junior PHP programmer. I was working here for about five years, and the main lesson I have learned was that education is nothing compared to real work experience.

The next page of my professional life was my work in outsourcing (PHP and Ruby on Rails). And then I found Node.js. It was something that I always wanted: processes that do not have to wait for DB/IO operations, which are keeping all the resources, but doing something useful instead. That’s why I started using it — it’s more efficient compared to synchronous programming environments. By “efficient” I don’t mean speed of processing, but rather more flexibility in programming style.

As a good example of its flexibility, I can share some solutions I recently programmed for a Redis adapter for the Jugglingdb ORM. The problem: during peaks in website usage, we are running a lot of db queries to serve pages, and most of the queries are the same. The obvious solution is to cache results of the queries, but this solution requires additional coding and some logic for cache invalidation.

We’ve come up with a better solution: cache queries and not results. When a query comes, we don’t execute it immediately; instead, we wait for some time, collect identical queries, then execute the query once and run multiple callbacks to serve all clients. This solution is simple and requires no additional logic. As a result, we have flat db usage, even during peaks. This solution is natural in Node.js, and that’s why Node.js rocks!

Life after discovering Node.js was great, full of interesting challenges and work, but one thing was annoying: each time I start a new project, I have to do almost the same work to organize code. For me, as a Rails developer, it’s really great to be able to create well-structured MVC applications fast, generate scaffolding controllers/views and other stuff. But this kind of tool was missing in Node.js and that’s why I spent my Christmas holidays writing it. The project was called express-on-railway at first, then RailwayJS, then CompoundJS.

The main goal of the project was to bring structure to an Express.js application, add the ability to extend applications in a standard way, and generate application code. So, it was not a new framework, but just Express.js with decent MVC structure, which is good for developers who don’t need to learn anything but Express.js to be able to understand what’s going on in a CompoundJS application. And it was a kind of piggybacking on Express.js and Rails experience. The idea was to get the best ideas from Rails and bring them to the node platform, and Express.js was selected as the base because it is the most popular framework for Node.js, and it has a relatively big community, so I wouldn’t be alone with my “new framework.” It was the start of my open-source years, which completely changed my attitude toward programming (and other life matters), but that’s another story.

And what can I say to conclude: web development in Node.js started with Express.js. It is a minimalistic and robust framework that gives you all you need to build decent web applications. Even if you decide to move to some more advanced frameworks at some point, Express.js knowledge is still a basic skill you have to learn. In addition, this book contains everything you need to know to start using Express.js. It clearly explains all concepts, as well as the answers to the most frequent questions that newcomers ask. For these reasons, this book is a must-read!