node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]

前端 未结 13 1750
长情又很酷
长情又很酷 2020-11-28 20:03

[add] So my next problem is that when i try adding a new dependence (npm install --save socket.io). The JSON file is also valid. I get this error: Failed to parse json

13条回答
  •  遥遥无期
    2020-11-28 20:19

    This can be resolved in another way:

    app.get("/", function(req, res){
    
        res.send(`${process.env.PWD}/index.html`)
    
    });
    

    process.env.PWD will prepend the working directory when the process was started.

提交回复
热议问题