Open ufologist opened 7 years ago
现在express的教程比较多... koa的 function *(){} 和yield都不熟悉
@px0078 Express 确实是最流行的, 生态资源相当丰富, 如果是第一次接触后端开发, 可以试一试. Koa 的话算是另一种尝试了, 功能比较单一, 虽然是 Express 团队做出来的, 但生态圈还是差了一大截, 总体来说还不如直接上 ThinkJS
为了前后端分离和SEO,在尝试前端同构,尤雨溪的示例就是express的,所以打算照着他的改 https://github.com/vuejs/vue-hackernews-2.0
Sails.js 请先做个自我介绍吧
Sails.js
ThinkJS
对比下 ThinkJS, 可以看到 Sails 的功能更为强大, 当然也就会更加地复杂...
新建一个项目跑起来
具体文档请参考官方的 Getting Started, 新建项目成功后访问
http://localhost:1337/
来查看效果, 以下示例基于sails@0.12.11
版本由于 Sails 没有自带 autorealod 功能, 开发阶段你修改代码后必须每次重启
sails lift
, 这样实在是太麻烦了, 因此推荐开发阶段推荐使用 nodemon 执行nodemon app.js
来自动重启, 另外sails console
是一个非常实用的命令行工具.官方提供的文档只是做了分类, 没有向导似的文档, 让你可以一步接一步从入门到进阶, 因此文档看起来会让人觉得混乱费劲, 建议先从 Controllers 看起.
Controllers
完整的 controller 示例
列举了一般开发中所需要的功能
重点内容
听听吐槽
其他选择
Express
提供了很好的路由模块化组织方式, 具体代码可以参考 expressjs/generator
Koa
Koa 没有自带路由中间件, 可以使用 koajs/route 这个简单的实现, 不过一般推荐使用 koa-router 功能更全.