This book is dedicated to my Mum and Dad.
To my Dad for his endless patience in driving me to rowing, martial arts, and tennis practice, and for his never-ending support.
To my Mum for cooking dinner with one hand and sketching out the basics of object-oriented programming and database normalization with the other.
Preface
One of the difficulties I had when trying to learn Node.js was how to get started. The references that I found either dealed with quasi-academic topics such as datagrams and event emitters, or else myopically focused on a topic without regard for the big picture. This book takes you through the complete process of building an application in Node.js. It starts with the canonical Hello World example, and goes on to build a real-time web application capable of sending trading information to thousands of connected clients.
What make Node.js different? First, it provides a unified language between the back end and front end. This means that all your thinking can be in a single language, with no cognitive overhead when switching from front end to back. Furthermore, it allows for shared code libraries and templates. This opens up a lot of interesting possibilities, the surface of which is just beginning to be properly explored.
Second, its fast. One of the common complaints of interpreted languages such as PHP, Python, and Ruby is speed. Jason Hoffman, CTO of Joyent, has discussed how Node.js is at the point where its performance can break operating systems. A single core with less than 1GB of RAM is capable of handling 10GB of traffic and one million connected end points. Combining 24 of these into a single machine produces an overall level of throughput that exceeds the capacity of operating systems and TCP/IP stacks. In other words, with a properly designed application its not Node.js thats the bottleneckits your operating system.
Third, its nonblocking architecture is made for the real-time web. JavaScript was chosen as a language because its based on nonblocking callbacks and has a very small core API. This means it was possible to build the entire Node.js ecosystem around nonblocking packages, of which there are currently in excess of ten thousand. The end result is a platform and ecosystem that architecturally fits perfectly with the modern demands of the real-time web.
I trust by now that youre excited by the possibilities of what Node.js can do for your real-time application. By the end of this book, Im confident that youll have the skills to be able to start dissecting and solving all but the most esoteric of problems. There is no greater joy in software than solving a complicated task and thinking at the end of it, That was all I had to do! It is one Ive experienced many times working with Node.js, and its my hope that you enjoy the same satisfaction both throughout the book and in using Node.js to solve your real-world problems.
Who Should Read This Book
This book is aimed at two target audiences. You might be a front-end engineer who is interested in looking at server-side development. An existing knowledge of JavaScript will prove useful, even if you are unfamiliar with certain server-side engineering techniques. Rest assured that by the end of the book, the topic will be covered in sufficient detail for you to know how to apply your front-end skills to back-end problems.
The second potential reader is the server-side engineer who uses another language such as PHP, Python, Ruby, Java, or .NET. The main benefit youll derive is seeing how your existing architectural, design, and pattern knowledge is applied to the world of Node.js. You may have little to no knowledge of JavaScript, but this should pose no big hindrance. By design, its an easy language to learn, and we will have covered many examples of both its syntax and idiosyncratic features by the end of the book.