nodejs路由可通过什么模块实现的
时间:2022-02-11 17:20
nodejs路由可通过url模块实现。url模块用于处理客户端请求过来的URL,nodejs中可通过url模块对url地址进行解析,从而实现路由的操作。 本教程操作环境:windows7系统、nodejs 12.19.0版,DELL G3电脑。 nodejs 的路由 路由指的就是我们要针对不同的URL有不同的处理方式。 URL模块作用:处理客户端请求过来的URL nodejs可通过 url 模块对 url 地址进行解析, 实现路由的操作 更多node相关知识,请访问:node教程!! 以上就是nodejs路由可通过什么模块实现的的详细内容,更多请关注gxlsystem.com其它相关文章!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 ....')
})