zoukankan      html  css  js  c++  java
  • Node.js学习(15)----Express 3.x和Express 2.x区别

    Node.js中Express框架变化还是挺大的。

    学习一个还未成熟的技术还是有很大风险的,但也具有挑战。

    Express 2.x过渡到Express 3.x

    删除的:

     1: res.render() "status" option (use node's res.statusCode= or res.status(code).render(...))
       2: res.render() "charset" option (use res.charset=)
       3: res.local(name, value) (use res.locals.name = value or res.locals({ name: value }) instead)
       4: app.dynamicHelpers() (use middleware + res.locals)
       5: app.helpers() (use app.locals)
       6: the concept of a "layout" (template engine specific now)
       7: partial() (template engine specific)
       8: res.partial()
       9: "view options" setting, use app.locals
      10: "hints" setting
      11: req.isXMLHttpRequest (use req.xhr)
      12: app.error() (use middleware with (err, req, res, next))
      13: req.flash() (just use sessions: req.session.messages = ['foo'] etc)
      14: connect-flash can be used as middleware to provide req.flash()


    变化的:

    1: req.header(field[, defaultValue]) replaced by req.get(field) (remains for backwards compatibility)
       2: res.header(field[, value]) replaced by res.set(field, value) / res.get(field) (remains for backwards compatibility)
       3: res.send(body[, code]) is now res.send([code,] body)
       4: res.redirect(url[, code]) is now res.redirect([code,] url)
       5: res.json(obj[, code]) is now res.json([code,] obj)
       6: renamed app.register() to app.engine()
       7: template engine compliance from engine.compile(str, options) => Function to engine.__express(filename, options, callback)
       8: express.createServer() is now simply express() (but remains for BC)
       9: Use express.cookieParser('secret') instead of passing the secret to the express.session() middleware. The 'secret' option in the express.session() middleware has been removed.



  • 相关阅读:
    路径操作OS模块和Path类(全)一篇够用!
    数据可视化:绘图库-Matplotlib
    matplotlib中文显示的问题
    Microsoft Visual C++ 14.0 is required问题解决
    python习题——随机整数生成类
    python——时间模块
    怎么获取10个线程的结果再返回
    集群服务器定时任务,只运行一个定时器的设计
    分布式事务
    分布式数据库---分库分表
  • 原文地址:https://www.cnblogs.com/phisy/p/3363752.html
Copyright © 2011-2022 走看看