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