FrontEnd/JavaScript
[ Socket.io ] node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
SangHoonE
2022. 1. 11. 15:21
nodejs로 서버를 구성하고, socket.io 를 통해서 웹소켓을 구성하려고하는데 해당 에러가 발생하였다.
node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
이유인즉슨, result.sendFile( ) 에서 [절대 경로 설정 or Root 경로 설정] 을 해주지 않았기 때문이다.
(라고 stackoverflow에서 말함)
그래서 해결방법은 간단하다.
__dirname 을 추가해주면 된다. -> 요청한 경로를 따라옴
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
일단 그래서 해당 에러는 해결이 되었다.
node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
[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 npm ERR! Unexpected string n...
stackoverflow.com
반응형