2014年7个流行的 Node.js Web 框架
Node.js or most commonly know as Node, is a JavaScript platform that allows you to build large scale web applications.
Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Hello World in Node.js
The following code will start a web server through Node and print out the text ‘Hello World’ when someone views localhost:8080
It’s quite amazing how far the technology has evolved.
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n'); }).listen(8080); console.log('Server started'); |
I do however understand that you most likely already know all this, and instead want to get straight to the list of frameworks. Lets get to it.
Why a Web Framework
Generally, frameworks are created to save people a lot of unnecessary work. The many functions of a web framework allow to further create applications, and then allow the community to interact with each other to increase the functionality and the availability of that given framework.
I’ve not discussed many programming matters here on CodeCondo, but I hope to start improving upon that very idea. We all have to start somewhere.
7 Minimal Node.js Web Frameworks
You can transfer me ten million dollars right away to bump your framework on top of the list, other than that – these are all genuine choices of myself and I do not represent any of the companies and communities listed below. I’ve got huge respect for the people that are involved with these projects, as they’re the ones helping and making the web become a better place.
Didn’t find your favorite Node.js framework on the list? Just leave a comment and we can discuss the matter further. :)
note: all of the frameworks in the list are under The MIT License (MIT)
Express – node.js web application framework
The idea behind Express is to provide an accessible and lightweight framework that you can use to build both large and small, hybrid applications for the web. It’s a well known Node.js web framework that’s used by recognized brands such as:
- MySpace
- Storify
- Countly
In fact, the blogging platform ‘Ghost‘ was built by using the Express framework.
If you’re looking for something easy to use that doesn’t require or force you to use external templates, Express might be a good place to start. Have you used Express before?
Flatiron, A framework for Node.js
Flatiron is a framework that is supported with a generous sponsorship from the Nodejitsu project, and of course communities all around the world. Flatiron was put together in order to diversify how web applications are created, but also to provide a stable framework for building something modern and reliable.
The post from Charlie Robbins really explains this framework well. You can read it here.
An initiative to build a collection of decoupled tools with the same standard of quality and performance that you would expect from anything built by Nodejitsu.
A full-stack web application development framework which packages these tools together to make isomorphic and stream-based application development easier.
Flatiron provides a ton of resources and useful gadgets to provide the best possible environment for both experienced and inexperienced Node.js users (coders).
Koa – next generation web framework for node.js
Koa is actually a web framework that’s being developed and maintained by the original team behind Express, the first Node.js framework I listed on this post. We clearly see the trend of evolution forming rather quickly, and Koa is no exception.
A Koa application is an object containing an array of middleware generator functions which are composed and executed in a stack-like manner upon request. Koa is similar to many other middleware systems that you may have encountered such as Ruby’s Rack, Connect, and so on – however a key design decision was made to provide high level “sugar” at the otherwise low-level middleware layer. This improves interoperability, robustness, and makes writing middleware much more enjoyable.
Koa is set to stand out from the crowed by not utilizing any middleware within the frameworks core, and allowing to use a set of elegant and modern methods that should make server launching much more interesting and appealing.
The reason that Koa isn’t the new Express 4.0 is because of the fundamental design changes which would make it impossible to transfer from 3.0 to 4.0 without making drastic changes, like rewriting the whole framework.
total.js / web framework for node.js
total.js is a very modern minimal web framework for creating great Node.js applications. It’s designated for people who are interested in creating large scale web applications that are both elegant and up-to the latest web standards.
It is an incredibly robust and feature rich framework that you should definitely check out, perhaps only for the great examples it provides, to give you a glimpse of the possibilities. There is also a huge video section dedicated to teaching you the tricks about the total.js framework.
You can learn a lot more about this framework on the homepage (linked earlier) or the official GitHub page.
restify – building REST APis with Node.js
This one is pretty straightforward, and I felt obliged to include it in the list, as it serves one purpose and servers it very well. You’ll find on the official restify guide page an explanation as to why is this framework more appealing than Express, when it comes to creating REST API for your applications.
UPDATE: 18/03/2014
I’ve recently gotten in touch with Eric Elliott, who’s very much into JavaScript and in fact Node.js too, and he had this to say about restify.
Restify makes lots of the hard problems of building such a service, like versioning, error handling and content-negotiation easier. It also provides built in DTrace probes that you get for free to quickly find out where your application’s performance problems lie. Lastly, it provides a robust client API that handles retry/backoff for you on failed connections, along with some other niceties. – Marc Cavage
http://blog.nodeknockout.com/post/34710903021/restify
Restify is not as mature or well documented as Express. Large parts of the public API surface are undocumented, and there are a lot fewer answers about it on StackOverflow. Common problems such as proper error handling are difficult to learn about. Plan to spend a lot of time searching the sourcecode for answers to questions.
That said, given the chance, Marc Cavage (the author) is responsive and helpful. I would encourage interested Restify users to help expand the documentation.
– Eric
SocketStream – a fast, modular Node.js web framework
I can’t say I disagree with the statement of real-time web. We’ve seen it happen and change gradually over the last couple of years, and with applications like Node.js – it’s even easier to make that statement a reality. SocketStream is exactly what is says it is, a fast and minimal framework for building real-time one page applications.
By taking care of the basics, SocketStream frees you up to focus on building your social/chat app, multiplayer game, trading platform, sales dashboard, or any kind of web app that needs to display realtime streaming data. All personal tastes (e.g. Vanilla JS vs CoffeeScript, Stylus vs Less) are catered for with optional npm modules that integrate perfectly in seconds, without bloating the core.
There isn’t a whole lot of activity on the website itself, but there SocketStream GitHub page is pretty busy.
Sails.js | Realtime MVC Framework for Node.js
Finally, the last one! I was getting tired of putting these together!
Just kidding, I loved it and I hope to publish an updated version before the end of the year. I think we’ll see a lot of growth within this market as the community support and demand is there.
Sails.js make it easy to build custom, enterprise-grade Node.js apps. It is designed to mimic the MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with scalable, service-oriented architecture. It’s especially good for building chat, realtime dashboards, or multiplayer games.
I’ll avoid rambling on about how great this framework is, and rather give you this video to watch to see some real life examples:
MinimalNodeJSWebFrameworks.close()
There have been some changes as to who is going to run and maintain Node.js in the future. You can read about the recent leadership changes on the official Node.js blog. I think that for the most part it doesn’t change all that much, the new project leader Timothy has been around Node for a while, and it only makes sense that the position was given to him.
Either way, did I miss any good frameworks?
UPDATE: 09/02/2014
I said I would update the post once more people shared their opinions and take on it. I am incredibly grateful for the thousands of people who managed to find this post, and share it with the world. Thank you Reddit, Node Weekly and all the lovely people on social media for helping me to spread the word.
Here is a list of links that people left in the comment section, all of which are more resources for great Node.js web frameworks. I am open to suggestions for future posts based on similar concept like this. Thank you!
http://geddyjs.org/
http://compoundjs.com/
http://towerjs.org/
https://github.com/WebReflection/polpetta
http://actionherojs.com/
http://spumko.github.io/
http://nodewebmodules.com/