Learn how to run Node.js on Engine Yard Cloud.
Node has grown beyond buzz in recent months to become the go-to technology for rapid and highly scalable web application deployment. It is currently the second most-watched open source project on GitHub, and the number of developers releasing open source Node modules has grown five-fold in the past year. Startups are also flocking to Node as the technology of choice to quickly make their dream applications a reality.
Node.js is also gaining traction in the enterprise. LinkedIn has been vocal about using Node to power the server-side stack of the company's mobile application. LinkedIn went from running 15 servers with 15 instances on each physical machine to just 4 instances that can handle twice the traffic.
eBay has also adopted Node for ql.io, a data-retrieval and aggregation gateway. Benchmarks by eBay indicate that the company can support 120,000 active connections per Node process on a standard workstation.
Modules, Dependencies and Collaboration: The Node Way
Node's module system was built from the ground up to provide the cleanest possible experience for team collaboration and application deployment. Furthermore, many Node module developers have fully embraced the single responsibility principle to ensure a DRY codebase and high test coverage.
The Node Package Manager (NPM) is an online repository of open source modules that can be used as the basis for any Node application. By using the NPM command line utility included with Node, developers can easily publish their own modules or install and upgrade project dependencies. Node's implementation of local, recursive dependency resolution ensures that each application maintains its own dependency tree.
Each Node module includes a
package.json file which specifies that module's meta data, including its dependencies. Node will recursively select the best-fit version of a dependency based on that module's specification. Each module being used within the scope of a larger application will function exactly as the original developer intended.
The Node ecosystem is evolving rapidly, and modules are being updated quite frequently. While there is much to be said for staying "bleeding edge," when deploying mission critical applications or collaborating in teams, a reasonable expectation is that every installation be identical. Rather than leave this to chance or checking dependencies into version control, NPM includes a command called
shrinkwrap to recursively lock all dependency versions.
The NPM repository is at 12,000 modules and growing daily. To read more about NPM and browse available packages, please visit the NPM website.
Though you can easily create a basic web server in Node with about four lines of code, the final section of this article will cover notable modules that can help you get your application up and running quickly.
Though there are many different frameworks for getting a Node web application started, Express by TJ Holowaychuk is by far the most prolific. Originally inspired by Ruby's Sinatra framework, Express is a middleware-based asynchronous web application module. It includes a number of middleware components such as a router, session/cookie handlers, form and query string parsing and template rendering. It can also be easily extended with custom middleware to accommodate whatever your need may be.
As previously mentioned, Node.js is perfect for real-time web apps. If you are looking to provide a robust real-time experience for your application then Socket.io by LearnBoost needs to be in your tool belt. Socket.io abstracts and expands on the HTML5 webSocket protocol by providing an API that can be used in any browser. For browsers or mobile devices that do not provide HTML5 WebSockets, Socket.io will gracefully fall back on to another transfer protocol (such as long-polling) to provide the same, real-time experience to all of your users. Socket.io also enhances the WebSocket experience with multiplexing, scaling strategies and broadcasting.