当前位置:网站首页>Express project creation and its routing introduction
Express project creation and its routing introduction
2022-07-19 01:41:00 【Don't null Yes】
Catalog
Express Project structure analysis
Express Introduce
Express It's the smallest , agile Node.js Web Application framework , It provides a powerful set of functions to develop Web And mobile applications . It helps to be based on Node Web Rapid development of applications .
Express Framework of the Core functions yes :
- Allow to set up middleware response HTTP request
- Defines a method for executing based on HTTP Methods and URL Routing table of different actions
- Allow dynamic rendering based on parameters passed to the template HTML page
install Express
install Express The framework is used globally npm, So that it can be used node Terminal creation Web Applications .
npm install -g express
Use Express Create project
Express Project creation
Use cmd Command window
1、 Enter working directory ( Customize )
2、 Execute the create command , Create a file called hello Of Express project --->express hello
Indicates the successful installation interface

3、 Get into hello Directory installation dependent packages :
F:\hello> npm install
4、 After installation , Execute the command to start the application :
F:\hello>npm start
5、 Enter... In the browser http://localhost:3000/

In the use of WebStorm When creating a project, directly select the project option as express You can directly create .
Express Project structure analysis
- bin: Startup profile , stay www Modify the operation port number in
- node_modules: Store all project dependency Libraries , It's like java Storage rack bag
- public: Used to hold static resource files picture ,CSS,JAVASCRIPT file ..
- routers: The routing file is equivalent to springmvc Medium Controller,ssh Medium action
- views: Where the pages are stored
- package.json: Projects depend on configuration and Developer Information .
- app.js: Apply core profile , Project entrance

Express route
Routing is used to determine how the application responds to client requests to specific endpoints , Contains a URI( Or the path ) And a specific HTTP Request method (GET、POST etc. ).
Each route can have one or more handler functions , These functions are performed during route matching . It is used in the following form :app.method(path,handler)
app : yes express Example ;
method: yes HTTP Request method
path: It's the path on the server
handler: It is a function executed during route matching
If There are multiple routing handlers , If it is not the last route , Its parameters should have next:

next() The function is not Node.js or Express API Part of , It is the third argument passed to the middleware function .next Function is mainly responsible for handing over control to the next middleware , If the current middleware does not terminate the request , also next Not called , Then the request will be suspended , The middleware defined later will not get the opportunity to be executed .
边栏推荐
猜你喜欢

XXX packages are looking for funding run `npm fund` for details解决方法

Differences between let and const, let, const and VaR

知名啤酒百威布局NFT,试图揭开“蓄谋已久”的上链面纱?

软件漏洞分析入门(二)

Uni app wechat official account (4) - address management page

一文盘点估值超过1亿美元的NFT项目

JS intercepts the first few digits of the string or the last few digits of the string

The applet is embedded in the web page, jumps to the applet and transmits parameters. The wechat applet realizes the authorization of official account to obtain openid

The use of libtomcrypt password Library

Introduction to software vulnerability analysis (III)
随机推荐
08-BTC-分叉
Assemblage stylisé de cartes de commutation auto - encapsulées
02_数据绑定
元宇宙会给万亿市场的音乐产业带来哪些变化?
tp-watermark. JS web page add watermark plug-in
Uni app wechat official account (4) - address management page
es6语法--解构赋值
XXX packages are looking for funding run `npm fund` for details解决方法
promise
05-BTC-网络
07_事件的基本使用
05 BTC network
uniapp开发App中上传图片直传oss
无数次踩坑安装AWVS
01_ Template syntax
04-BTC-实现
ipfs 文件持久化操作
普通异步发送代码编写
05_回顾Object.defineProperty
Express的使用方法,路由的匹配与使用