Second, the route
1. Open routes/index.js , which means capturing a GET request to access the home page:
and assigned to the corresponding route via app.js :
See here, open http://127.0.0.1:3000/users/to feel the meaning of a route:
routes/index.js File:
If our request is get, the path is '/' then it is rendered index.ejs this view, you can omit the suffix name. Ejs:
This means uploading the data to the Index.ejs and outputting it to the page.
2. View Views/index.ejs
You can see that the EJS fetch data is obtained by <%= data%>.
Ejs template here just remember:
Format <% Execution Method%>
The format <%-executes the method and outputs the result to the page%>
Format <%= output data directly to the page%>
3, back to the routes/index.js We continue to talk about
Express encapsulates a number of HTTP request methods, as follows:
Router.get get requests are often used for queries and page jumps
Router.post Post requests are often used for data submission (ADD)
Router.patch is often used for data modification
Router.delete often used for data deletion
Router.use Intercept All request modes
However, in general, small projects are generally get,post,use.
If you write an API service project, you need to add and delete the request to change the way separate,
That's why you use Router.patch,router.delete.
PS: Routing is the forwarding of methods .....
4. Remove users Routes
Delete these two lines in app.js
and delete the routes/users.js file
PS: Personal Site A route is good, otherwise the project structure is too fragmented
Route first here, see tell ...
Reprint Please specify: http://www.cnblogs.com/zhangmingze/p/4995933.html
node. js + Express + Mongodb Development Build personal website (ii)