인프런 커뮤니티 질문&답변
io is not defined
해결된 질문
작성
·
1.3K
2
const socket = io('/');
const getElementById = (id) => document.getElementById(id) || null;
// get DOM element
const helloStrangerElement = getElementById('hello_stranger');
const chattingBoxElement = getElementById('chatting_box');
const formElement = getElementById('chat_form');
function helloUser() {
const userName = prompt('What is your name?');
socket.emit('new_user', userName);
console.log(userName);
}
function init() {
helloUser();
}
init();
io is not defined라고 뜨면서 prompt가 나오지 않습니다. scripts.js의 1라인을 주석철히하면 prompt는 뜨구요.
어떻게 하면 해결할 수 있을까요?
(https://github.com/GroundP/random-chatting)
퀴즈
서버 사이드 렌더링(SSR)과 클라이언트 사이드 렌더링(CSR)의 가장 큰 차이점은 무엇일까요?
데이터 저장 위치
데이터 전송 방식
HTML 렌더링이 일어나는 주체
사용되는 프로그래밍 언어
답변 1
1
윤상석
지식공유자
안녕하세요!
https://github.com/GroundP/random-chatting/blob/master/views/index.hbs
이 부분이 문제인 것 같습니다!
scripts.js은 socket script 아래에 있어야 합니다! (scripts.js에서 socket 라이브러리를 사용하기 때문에) 지금 위 아래 둘 다 scripts.js가 삽입되어 있는데 위에 부분 지워주시면 됩니다!





.png?w=112)
감사합니다!