Review node(1)

The goal is to build a simple server, and go through node again.
I wrote this first sentence two days ago. Because it was probably a conceptual problem, it was not recorded, because there is a bit of demo and express involved. Now record it.

First record the special place of these two days
Insert picture description here
now:
Supplement 1: After modifying the code, it will automatically restart
nodemon to solve the problem of frequently modifying the code and restarting the server.
**Download: **npm i --global nodemon is
used after installation:
node app.js- -----》Nodemon app.js

Static service

Similar to routing, it feels like routing.
Insert picture description here

Configure the use of art-template engine in express

npm i --save art-template express-art-template

Configure the practical art-template template engine
. The first parameter indicates that the art-template template engine is used when rendering files ending with .art

app.engine('这里是后缀,写啥都行,就写.html得了', require('express-art-template'));

res.render('html template name', {template data})
The path cannot be written in the first parameter. By default, the template file will be found in the views directory of the project. That is to say, Express has a convention that developers put all The view files are placed in the view directory.
Insert picture description here

Here is the abbreviation for redirection, an api solution, res.redirect('/'). Redirect back to the first directory.
Insert picture description here
ok The others are the basics that I have learned, so I won't record them. I will start recording tomorrow because I haven't seen them. . . .

Guess you like

Origin blog.csdn.net/weixin_46013619/article/details/105180082