Can't open this page in nodejs? But I can open it directly with chrome.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="./a.css" rel="stylesheet" type="text/css"/>

</head>
<body>
    <h1></h1>
<script type="text/javascript" src="./c.js"></script>
</body>
</html>
var http = require("http")
var path = require("path")
var fs = require("fs")
var url = require("url")
var server = http.createServer(function(req, res){
    // console.log(req)
    // console.log(res)
    function staticRoot(){

        fs.readFile("./hello.html",function (err,fileContent){
    if(err){
        console.log(404)
        res.writeHead(404,"not found")
        res.end()
        }else{
             res.writeHead(200, "OK")
             console.log("OK")
            res.write(fileContent)
            res.end()}
})}
        staticRoot()

error clipboard.png

clipboard.png

Feb.28,2021

c.js also returns html, right? I don't see you make a difference.

Menu