Nodejs路由可通过什么模块实现的
2418
nodejs路由可通过url模块实现。url模块用于处理客户端请求过来的URL,nodejs中可通过url模块对url地址进行解析,从而实现路由的操作。
nodejs 的路由
路由指的就是我们要针对不同的URL有不同的处理方式。
URL模块作用:处理客户端请求过来的URL
nodejs可通过 url 模块对 url 地址进行解析, 实现路由的操作
- const http = requrie('http')
- const url = requrie('url')
- http.createServer((req, res) => {
- // 对请求的路径进行解析
- let pathname = url.parse(req.url).pathname;
- if(pathname == '/'){
- // 相关的处理
- }else if(pathname == '/login'){
- // 相关的处理
- }....
- }).listen(3000, () => {
- console.log('server runnning ....')
- })
本文网址:https://www.zztuku.com/detail-10262.html
站长图库 - Nodejs路由可通过什么模块实现的
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!