The making of logic between page and page
Detailed code can be viewed in the actual combat folder in the Nodejs file (written by yourself)
1. Install everything you need at the root of the project with the command line
CD Program
NPM Install Express Jade Mongoose
2. Entrance file: app.js
var express = require (' Express ')//introduction of Express
var Port =process.env.port | | 3000
var app = Express ()
App.set (' views ', './views ')/Set the root of the view
App.set (' View engine ', ' jade ')//Configure View template engine (Jade)
App.listen (port)//Listening port
3. Template view file (Jade)
Create a view index.jade, Detail.jade, and so on in the Views folder (note indentation issues)
DocType
Html
Head
Meta (charset= "Utf-8")
Title #{title}//and title correspondence in routing
Body
H1 #{title}
4. Write routing in app.js file
App.get ('/', function (req,res) {
Res.render (' index ', {//index is the filename to render)
Title: ' MyProgram home '
})
})
App.get ('/movie/:id ', function (req,res) {
Res.render (' detail ', {
Title: "MyProgram Details page"
})
})
5, the use of Jade template inheritance, the public view of the part of the show.
This allows you to introduce templates directly to other pages, via include./includes/header
Header.jade Code:
. container
. row
. page-header
h1= title//flexibly #{title form}
Small Small title
Build a header file to store header information
Link (href= "/bootstrap/dist/css/bootstrap.min.css", rel= "stylesheet")
Script (src= "/jquery/dist/jquery.min.js")