Node.js distinguishes whether a file is requested or an interface.

const http=require("http")
const io=require("socket.io")
const mysql=require("mysql")
const fs=require("fs")
const url =require("url")

let  httpServer=http.createServer((request,response)=>{
    let {pathname,query}=url.parse(request.url,true)
    // truetruequeryjson
    if(pathname=="/reg"){
        console.log("")
    }else if(pathname=="/login"){
        console.log("")
    }else{
        console.log("")
        fs.readFile(`www${pathname}`,(err,data)=>{

        })
    }
})
httpServer.listen(8080)

when my browser typed http://localhost:8080/reg?user=abc12342&pass=a666666666, what I consoel.log out is the registration, file. Why is the "file" printed back?

Mar.14,2021

because there are two requests in the browser, one is the correct request as you think, and the other is to request the favicons small icon, so the 'file' will be printed.

Menu