281 points · by m0hit · 12y ago · 121 comments
5s: "designed by the team behind Express" (wait what?)
6s: "Through leveraging generators Koa allows you to ditch callbacks" (wow, ok. oh hey, that makes "next generation" not just marketing fluff)
18s:
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
this.set('X-Response-Time', ms + 'ms');
});
(oh sweeet)But this is something new that looks like it can be good. I've been wondering when it would be announced, as TJ has been working on it for a while: https://github.com/visionmedia?tab=activity
> next generation web framework for node.js
I don't think they need that, just list the stand-out features first. And yes, referring to past accomplishments does give it more credibility.
This might be one of the very few instances that "next generation" is a valid statement.
https://github.com/codegangsta/martini#next
// log before and after a request
m.Use(func(c martini.Context, log *log.Logger){
log.Println("before a request")
c.Next()
log.Println("after a request")
}) function(req, res, next) {
console.log('before');
next(); // go to the next middleware handler
console.log('after the middleware stack has been traversed');
}I can't wait to drop this in to one of my projects!
* stack traces of errors are useless? [1]
* missing catch filters/pattern matching i.e. catch (e) {} also captures type, reference and range errors i.e. "pokemon exception handling"?
[1]: http://spion.github.io/posts/analysis-generators-and-other-a...
It doesn't seem like they are useful yet:
1. The FAQ gives a political answer about the status of Express but I imagine that Express will not be actively maintained any more. Correct?
2. If focus is now on Koa, why the name change from Express when it is already a huge name for node frameworks?
3. If a new developer sees Express and Koa, would they immediately know which one is being focused on?
Basically I'm wondering why it couldn't be called Express 3.0 (or 4.0).
I also see pull requests getting merged into Express.js on almost a daily base. So I am not really worried about it dying anything soon. Most of the road map items for express are about extracting it's features into separate modules as well. Which means they are aiming at making the Express core even smaller and less opinionated.
I guess I'm more concerned about the marketing of this framework as there's now two names for the same thing except one is newer than the other. As a dirty analogy - if jQuery started to support yields instead of function callbacks, do they change the name of the library?
Looking at the syntax of Koa, it's still express except it looks nicer because there's no callbacks. What was the reasoning for ditching the big name? It can't be just for that.
EDIT: Answer: that's how "generator functions" are recognized. http://wiki.ecmascript.org/doku.php?id=harmony:generators
app.use(function *(next){
^
SyntaxError: Unexpected token *
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3Or use gnode, which will down-compile it to ES5 for current stable node.
It seems Express and Connect? http://stackoverflow.com/questions/3809539/choosing-a-web-ap...
And Express sits on top of Connect.
Koa is likely to replace Connect [0].
[0]: https://twitter.com/tjholowaychuk/status/369868946989535232
What other values can I yield, and why would I want to?
Alternatively, couldn't the `next` object just be a plain continuation?
if (user.isAuthenticated) doSomething()
vs
doSomething() if (user.isAuthenticated)
the first is less readable perhaps but I think it's more useful for a programmer. To each their own! Maybe some day I'll be convinced otherwise, I like it better for asserts too:
assert(200 = res.statusCode) assert('application/json' == res.headers['content-type'])
assert(res.headers['content-type'] == 'application/json')
looks weird to me now but maybe I'm just used to it
http://iampaddy.com/lifebelow600/
http://uxmyths.com/post/654047943/myth-people-dont-scroll
http://www.marketingexperiments.com/blog/analytics-testing/w...
I had to work with express, and one thing that I missed was having a Response object where you build your response and then pass back to the framework at the end of the request. So I built my own proof-of-concept-framework to understand why others don't do it (maybe it was just not possible).
Many people will tell you that there are a thousand frameworks out there, go contribute to one of those instead of creating more noise. For me doing a framework was a great way of learning the internals of node, the kind of things that frameworks are designed to hide away from you. Go for it, start your own open source framework and put your ideas into practice. The ecosystem is still maturing.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...
but there aren't any comparisons yet.
Node developers go home and fuck the prom queen.