
Koa – Next-generation web framework for Node.js - m0hit
http://koajs.com/
======
quarterto
0s: "next generation web framework for node.js" (oh god, not another)

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)

~~~
FooBarWidget
Reading this comment makes me sad. Does this mean you would have immediately
closed the tab, irregardless of technology, if they didn't namedrop?

~~~
quarterto
I was already giving it the benefit of the doubt by reading any further than
"next generation web framework for node.js".

~~~
easy_rider
Couldn't agree more. Happy that I did though.

------
spion
Does koa (or co) solve the problem with generators where

* 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...](http://spion.github.io/posts/analysis-generators-and-other-async-
patterns-node.html#stack-trace-accuracy)

~~~
jongleberry
yes, stack traces work now, as long as they aren't being thrown in a different
event loop:
[https://github.com/koajs/koa/issues/117](https://github.com/koajs/koa/issues/117)

~~~
spion
Oops - I didn't mean thrown errors, I meant errors passed to the callbacks.

It doesn't seem like they are useful yet:

[https://gist.github.com/spion/356bfc9cc1089edd2e3b](https://gist.github.com/spion/356bfc9cc1089edd2e3b)

------
deif
I have some questions about this:

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).

~~~
ds_
I understand it's due to connect being bought by sencha. The FAQ states it's
more like connect, with some express goodies moved to the middleware level.

~~~
deif
But express _was_ connect with some extra goodies on top. Surely this is an
iteration upon express?

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.

~~~
ds_
If express was connect, since koa is basically a rewrite of connect using
generators, doesn't it make sense to give it a new name?

~~~
sehr
Express isn't Connect. Does it honestly even matter or are you just finding
something to nitpick?

------
zimbatm
What's the star in "function *(){}" for ?

EDIT: Answer: that's how "generator functions" are recognized.
[http://wiki.ecmascript.org/doku.php?id=harmony:generators](http://wiki.ecmascript.org/doku.php?id=harmony:generators)

~~~
vbv
Does node.js support the * though. I tried their example and getting this:

    
    
      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:3

~~~
baudehlo
It requires node v0.11.3 or above and the --harmony-generators flag at launch.

Or use gnode, which will down-compile it to ES5 for current stable node.

------
turingbook
Which Nodejs Web framework is the most popular in production? There are so
many choices: [http://nodeframework.com/](http://nodeframework.com/)

It seems Express and Connect?
[http://stackoverflow.com/questions/3809539/choosing-a-web-
ap...](http://stackoverflow.com/questions/3809539/choosing-a-web-application-
framework-using-node-js)

~~~
untog
FTA, Koa is made by the same people who make Express.

And Express sits on top of Connect.

------
Sheepshow
Not sure I understand the semantics. I'm passed what looks like a
continuation, but instead of calling it, I yield it?

What other values can I yield, and why would I want to?

Alternatively, couldn't the `next` object just be a plain continuation?

~~~
yojimbo311
zimbatm's link to
[http://wiki.ecmascript.org/doku.php?id=harmony:generators](http://wiki.ecmascript.org/doku.php?id=harmony:generators)
was helpful here.
[https://wiki.python.org/moin/Generators](https://wiki.python.org/moin/Generators)
seems to also have some useful background on where the semantics are coming
from.

------
camus2
If TJ is on board that's the only information you need to know, you cant go
wrong with any code that guy writes.

~~~
bryanlarsen
I often purposefully avoid TJ modules because many of them end up being
unmaintained. Before using a TJ project check the outstanding pull requests:
are there a large number of open useful looking PR's? Is there somebody
besides TJ merging into master: aka has he delegated a maintainer?

~~~
tjholowaychuk
Ryan left node a long time ago, people still use it, just because the original
author isn't involved doesn't make it a bad project

~~~
bryanlarsen
That's right. I don't really care if you're actively involved in the project;
I just want somebody you trust to be. Like any node shop we quite happily use
a bunch of TJ modules.

------
Kiro
Can someone explain why this is better than for example Express?

~~~
ds_
One way: It leverages generators, which helps in avoiding callback hell
([http://blog.alexmaccaw.com/how-yield-will-transform-
node](http://blog.alexmaccaw.com/how-yield-will-transform-node)) Koa is
written by the same author as express.

------
oinksoft
So much for "above the fold."

~~~
coldtea
Above the fold has been wrong and deprecated for about 5 years now:

[http://iampaddy.com/lifebelow600/](http://iampaddy.com/lifebelow600/)

[http://uxmyths.com/post/654047943/myth-people-dont-
scroll](http://uxmyths.com/post/654047943/myth-people-dont-scroll)

[http://www.marketingexperiments.com/blog/analytics-
testing/w...](http://www.marketingexperiments.com/blog/analytics-testing/web-
usability-long-landing-page.html)

------
rmrfrmrf
It's funny -- I love node.js for pretty much everything _except_ for web
frameworks. IMO Express, Koa, Sails, and Meteor are all lacking some kind of
_je ne sais quoi_... maybe I should try my hand at one as an open source
project...? Anyone have any good resources about framework design?

~~~
cnp
Check out Sails.js. It's under active development, but I've used it for a few
things and find it totally fantastic:

[http://sailsjs.org/](http://sailsjs.org/)

~~~
bwilliams
I haven't touched it ever since I saw you can create records with GET requests
by default. Did they ever fix that?

~~~
particlebanana
That has always been a config setting that should absolutely be turned off.

~~~
bwilliams
Is it default? I remember seeing the screencast when it was first gaining
traction and immediately dismissing it. That should be something that isn't
even included tbh.

~~~
krsunny
I think the benefits it provides outweighs the slight chance that someone
would ship code to production with it turned on.

~~~
cnp
I agree. It has been extremely useful during development

------
enen
Does anyone have a good read on generators? I have no idea what that is.

~~~
brickcap
MDN has a good explanation

[https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Guid...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Guide/Iterators_and_Generators)

------
rgbrgb
If anybody finds / does a benchmark, please link it here.

~~~
jongleberry
TJ just updated express' benchmarks to match koa's. here are the results on my
computer:
[https://gist.github.com/jonathanong/8065724](https://gist.github.com/jonathanong/8065724)

------
boultonmark
yawn

[http://www.tornadoweb.org/en/stable/gen.html?highlight=gener...](http://www.tornadoweb.org/en/stable/gen.html?highlight=generator)

~~~
ds_
Python has had generators since 2.2, where as they are just landing in
js/node.js.

~~~
bottompair
Python developers always whine about doing their best.

Node developers go home and fuck the prom queen.

~~~
retr0h
AND the queens name happens to be Rosie Palm

