Implement the Node. js Development Guide demo Based on the jade template and the new version of Express3.2.5

Source: Internet
Author: User

It took two weeks to learn about Node. js. I mainly studied Node. js Development Guide and implemented the examples in the book. The examples in this book are based on node. js v0.6.12 and Express v2.5.8, and I learned about node. js v0.10.7 and Express v3.2.5. I did not specifically compare the differences between these versions. However, the example in the book is implemented based on the new version. This blog is mainly used to share the differences between the current version and the version implementation example in the book:

1. ejs templates and jade templates

Since express is also the author of jade, the default template has been changed to jade since express3.0. Jade is not that complex. You can use the jade Project address to quickly get started. Note the following for the MicroBlog example in the book:

(1) title in layout. jade

Head title = title + '-Microblog'

(2) The value passing problem of success and error in layout. jade. Express3.0 does not support the flash method by default. You need to add a reference to connect-flash (directly use npm install connect-flash). Then, add the following code to app. js:

App. use (flash (); app. use (function (req, res, next) {res. locals. error = req. flash ('error'); res. locals. success = req. flash ('success'); res. locals. user = req. session. user; next ();});

(3) fragment view (partials) can solve this problem in two ways. One is to add a reference module through npm install express-partials, and the other is to replace it with include. I use the second method

Add say. jade ...... You can directly write include say in index. jade.

Source code download

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.