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
반응형
'FrontEnd > JavaScript' 카테고리의 다른 글
[ JavaScript ] 무던한 개발자를 위한 모던한 자바스크립트 (0) | 2022.02.09 |
---|---|
[ Node.js ] Express, WebSocket 구현하기 (0) | 2022.01.20 |
[ WebSocket ] Ubuntu + Apache + nodeJS 웹소켓 구현 / 기본 포트(8080)에서 다른 포트(3000) 띄우기 (0) | 2022.01.10 |
[ Node.js & Javascript ] WebSocket 서버와 클라이언트 구현하기 - 짧은 예제 / How to create server & client by Websocket? (0) | 2022.01.04 |
[node.js / ws] Websocket 사용하기, 내용 정리 및 예제 / How to use Websocket (0) | 2021.12.29 |