Using express to develop a socket.io chat server in node.js, the problem of file path in app.js

Terminal error: Path must be a string. Received null

clipboard.png

it feels like a problem with _ _ dirname, but I still reported an error after I changed it to the relative path. I would like to ask the great god to guide the rookies who have just learned node. Thank you very much.

under app.js:

var app = require("express").createServer(),
    io = require("socket.io").listen(app);

app.listen(1111);

app.get("/",function(req,res){
    res.sendfile(__dirname+"/index.html");

});

io.sockets.on("connection",function(socket){
    socket.emit("welcome",{text:"hello world!"})
})

under index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>socket.io  chatting!</title>
    <script src="/socket.io/socket.io.js"></script>
</head>
<body>
    <h1>let"s chatting~</h1>
    <script>
     var socket = io.connect();
     socket.on("welcome",function(data){
         console.log(data.text);
     })
    </script>
</body>
</html>

res.sendfile (_ _ dirname+'/index.html');

path paths do not use absolute paths. If you want to use absolute paths, use options configuration item root to configure

for example:

 var options = {
    root: __dirname + '/',
  };
res.sendFile('index.html', options);

or directly implement the relative path

res.sendFile('/index.html');

you can try

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36264-2ad35.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36264-2ad35.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?