Node 在Kiwi Support (Kiwi运营系统)中的应用

shellzhang
2014-1-21

概述

    • node一些基础
    • kiwi support中会用到的一些node组件
    • 开发模式介绍
    • 参考资料

Node基础

    • 关于Node的来龙去脉,可以看叔和实践
      • 《Node.js开发指南》—— byvoid (郭家宝)
      • 《深入浅出Nodejs》 ——  朴灵
    • 有了node
      • JSer的福音,尝试服务器端开发
      • 运营平台、CMS
      • 前端运维工具:grunt
      • 新的前端技术的尝试平台:AngularJS, Bootstrap...
      • 最重要的——为了更好的沟通
        • 是让JSer了解后端开发,不需要精通或者取代,而是理解与你合作的后端工程师角色,他们是如何思考的
    Kiwi Support中用到的一些node组件

      • express
      • ejs
      • sequlize
      • execSync
      • mongoose?

      express

        • 服务器端MVC框架,流行易用
        • 入口app.js
          • 配置基本模块(db, 模板, 静态资源等)
          • 配置路由(controller)
        • controllers
        • templates
        • models
        • 直接看实例

      ejs

      Ejs - Why?

        • Not the fastest
        • Some feature not supported well
        • Some plugins for ejs are not maintained
        • but why?
          • 易用性,与Kiwi前端模板语法类似,容易上手
          • 对于KiwiSupport来说,渲染性能不是首要考虑的
        • <%= xxxx%>与<%- xxxx%>的区别
          • 前者escaped
          • 后者没有
          • 有点像Kiwi中<%=%>与<%$=%>

      sequelize

        • An ORM framework to easy access DB
        • Similar with SQLAlchemy in Python
        • Example will be shown later...

      execsync

        • 这个只是一个同步执行外部命令的小模块
        • 在KiwiSupport中的作用
          • 调用python命令
            • 获取必要的配置参数
              • config/__init__.py中的DB1,MONGO_CLUSTER
            • gauth验证
              • admincore.gauth_des.decrypt
              • admincore.get_login_url
        • 目的
          • 与已经完备的系统进行对接,采用统一的配置信息
          • 避免不必要的重复开发

      开发模式介绍

        • repo: http://hgserver/palendar_nodejs/ 
        • 定义Model
          • model目录下
            • 一个model实例,一个js文件
        • 定义Controller
          • controllers目录下
          • exports.xxxx = function(req, res, next)
        • 规定路由映射——url到controller的对应规则
          • app.js
          • app.get, app.post, or app.all
          • 内部使用,需要auth
            • app.get('/url', auth(['devlogin', admin], controller.xxxx))
        • 定义模板
          • templates目录下
          • 继承自layout.ejs

      参考资料





      Thanks!

      Node in KiwiSupport

      By shellzhang

      Node in KiwiSupport

      Node tech in Kiwi Support System

      • 817