Develop a complete project note with Node.js+express.js+mongodb+jade (1) "page is the logical production between pages" __js

Source: Internet
Author: User
Tags mongodb

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")

Related Article

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.