10 ms·
Koa – Next-generation web framework for Node.js
- quarterto 13y ago0s: "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)
- mateuszf 13y agoSo, does node support generators out of the box?
- quarterto 13y agoIt's behind a flag (--harmony-generators) in 0.11 (current stable is 0.10, hence my "next generation" comment).
- FooBarWidget 13y agoReading this comment makes me sad. Does this mean you would have immediately closed the tab, irregardless of technology, if they didn't namedrop?
- quarterto 13y agoI was already giving it the benefit of the doubt by reading any further than "next generation web framework for node.js".
- easy_rider 13y agoCouldn't agree more. Happy that I did though.
- usethis 13y agoit's because of the hyperbole: > 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.
- eknkc 13y agoThis utilizes generators heavily. Generators are within the ES6 spec, which is the next generation of JavaScript. This might be one of the very few instances that "next generation" is a valid statement.
- mathrawka 13y agoToo many things claim to be a "next generation framework", that it usually is a let down because it is just a rehash of something. 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 https://github.com/visionmedia?tab=activity
- RivieraKid 13y agoI would.
- sergiotapia 13y agoOfftopic: *irregardless is not a word, Just use regardless.
- ehsanu1 13y agoLike it or not, irregardless is here to stay. Languages change, mispellings become the correct way to spell things, words become their own antonyms, and a lot of other very strange things. Embrace it!
- swalkergibson 13y agoI reject your implication. Just because a lot of people use it does not make it grammatically accurate. http://en.wikipedia.org/wiki/Irregardless http://en.wikipedia.org/wiki/Irregardless
- JangoSteve 13y ago> Just because a lot of people use it does not make it grammatically accurate. Actually, that's exactly what it does... over time. Where exactly do you think our language, as it exists today, came from?
- ds_ 13y agoAn interesting read on the subject: http://www.amazon.com/The-Unfolding-Language-Evolutionary-Invention/dp/0805080120 http://www.amazon.com/The-Unfolding-Language-Evolutionary-In...
- swalkergibson 13y agoOf course language evolves, but a double-negative is a double-negative, no matter how you slice it. Do you have another example of a single word that is a double-negative?
- nekopa 13y agoUnless?
- tolas 13y agoYou don't believe in social proof and a history of success?
- dlau1 13y agoIt looks almost like if they rewrote express for generator functions I can't wait to drop this in to one of my projects!
- Gigablah 13y agoSaw something similar in Martini (golang): https://github.com/codegangsta/martini#next 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") })
- bjconlan 13y agoI don't think this yields the current thread/routine though does it? I think what you are seeing here is closer to express': function(req, res, next) { console.log('before'); next(); // go to the next middleware handler console.log('after the middleware stack has been traversed'); }
- andreypopp 13y agoI think does yield as stated in docs. Go have coroutines so there is no need in generators.
- flym4n 13y agoThat's using a callback, like express or connect does. What's new in koa is the use of js generators
- jerf 13y agoGo doesn't need JS generators. It already handles execution flow correctly. It is not correct to assume the Node execution model holds everywhere; we've made a lot of great advances since the old event-based model was invented in the 70s. That actually wraps the full handler without any need to jump through event threading hoops, and is not "blocking", in the sense that the Node community uses the term. That's an out-of-the-box feature for a modern language.
- klibertp 13y ago> That's an out-of-the-box feature for a modern language. Or for any Scheme for the last 30 years, but don't let that change your views on how "modern" you language is :)
- joenied 13y agoI found the GIF on this page explains it pretty good: https://github.com/koajs/koa/blob/master/docs/guide.md https://github.com/koajs/koa/blob/master/docs/guide.md
- bsiddiqui 13y agopretty well
- deleted 13y ago[deleted]
- deif 13y agoI 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_ 13y agoI 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 13y agoBut 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_ 13y agoIf 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 13y agoExpress isn't Connect. Does it honestly even matter or are you just finding something to nitpick?
- brainflake 13y agoIt looks like some important express-like things are missing though. For instance, there is no routing abstraction or rendering. I think you're right that Express is connect with extra goodies, but the most important of those are missing from koa. Although branding it as a 'next-generation web framework' definitely seems like they want to replace express.
- camus2 13y agoIf TJ is on board that's the only information you need to know, you cant go wrong with any code that guy writes.
- deleted 13y ago[deleted]
- mradmin 13y agoI have utmost respect for TJ and his work but I am not a fan of his yoda style programming :(
- ds_ 13y agoWhat do you mean by that? if (constant == variable) type conditions?
- mradmin 13y agoYup, for example: https://github.com/koajs/koa/blob/master/lib/application.js#L168-L201 https://github.com/koajs/koa/blob/master/lib/application.js#...
- ds_ 13y agoIt does seem strange, is there a reasoned argument for why this can be better?
- dhyasama 13y agoThe two reasons I've heard are preventing accidental variable assignment and preventing null references. Personally, I don't think either of those things outweigh the readability issue.
- klibertp 13y agoBut you do know why this style exists and what benefits it has?
- Kiro 13y agoCan someone explain why this is better than for example Express?
- ds_ 13y agoOne 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.
- untog 13y agoIt's made by the same people who made Express. It seems like it's an off-shoot that uses generators, something that would be difficult to do in Express.
- spion 13y agoDoes 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-async-patterns-node.html#stack-trace-accuracy http://spion.github.io/posts/analysis-generators-and-other-a...
- jongleberry 13y agoyes, 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 13y agoOops - 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
- zimbatm 13y agoWhat'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
- goldenkey 13y agoThanks, I was wondering the same thing. "A function named star you say?" Heh :-)
- vbv 13y agoDoes 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
- deleted 13y ago[deleted]
- boultonmark 13y agoyawn http://www.tornadoweb.org/en/stable/gen.html?highlight=generator http://www.tornadoweb.org/en/stable/gen.html?highlight=gener...
- ds_ 13y agoPython has had generators since 2.2, where as they are just landing in js/node.js.
- sehr 13y agoYeah, strangely enough not all languages/libraries develop functionality at the same time. It's weird, I know.
- bottompair 13y agoPython developers always whine about doing their best. Node developers go home and fuck the prom queen.
- retr0h 13y agoAND the queens name happens to be Rosie Palm
- deleted 13y ago[deleted]
- turingbook 13y agoWhich 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-application-framework-using-node-js http://stackoverflow.com/questions/3809539/choosing-a-web-ap...
- sehr 13y agoI'd guess Express. It's in use at quite a few high profile companies, and most other frameworks are just built on top of it.
- untog 13y agoFTA, Koa is made by the same people who make Express. And Express sits on top of Connect.
- prezjordan 13y agoExpress is probably the most popular in terms of apps deployed, and sits on top of Connect. Koa is likely to replace Connect [0]. [0]: https://twitter.com/tjholowaychuk/status/369868946989535232 https://twitter.com/tjholowaychuk/status/369868946989535232
- rmrfrmrf 13y agoIt'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 13y agoCheck 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 13y agoI haven't touched it ever since I saw you can create records with GET requests by default. Did they ever fix that?
- particlebanana 13y agoThat has always been a config setting that should absolutely be turned off.
- bwilliams 13y agoIs 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.
- rgbrgb 13y agoIf anybody finds / does a benchmark, please link it here.
- jongleberry 13y agothere's a silly benchmark in the repo: https://github.com/koajs/koa#benchmarks https://github.com/koajs/koa#benchmarks but there aren't any comparisons yet.
- jongleberry 13y agoTJ 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
- Sheepshow 13y agoNot 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 13y agozimbatm'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.
- oinksoft 13y agoSo much for "above the fold."
- coldtea 13y agoAbove 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/web-usability-long-landing-page.html http://www.marketingexperiments.com/blog/analytics-testing/w...
- enen 13y agoDoes anyone have a good read on generators? I have no idea what that is.
- brickcap 13y agoMDN has a good explanation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...