우리의 목표: 자바스크립트를 이용해서 Node.js가 갖고 있는 기능을 호출하여 우리가 웹 애플리케이션을 Node.js로 만들 수 있게하는 것.
이제 Node.js의 영역으로 넘어가서 웹 애플리케이션을 구현하는 아주 중요한 스킬을 알아보자.
=> 주인공은url이다.
URL의 형식
이미지 참조 : 생활코딩 Egoing Node.js 강의 (https://opentutorials.org/module/3549/21046)
1) Protocol : 통신규칙
사용자가 서버에 접속할 때 어떤 방식으로 통신할 것인가에 대한 부분.
HTTP : (Hyper Text Transfer Protocol) 웹서버와 웹브라우저가 서로 데이터를 주고 받기 위해서 만든 통신 규약.
2) Host (domain) : 호스트
인터넷에 접속되어 있는 각각의 컴퓨터를 호스트라고 부른다.
(opentutorials.org)는 특정 인터넷에 접속되어 있는 컴퓨터를 가리킨다.
3) port : 포트 번호
한 대의 컴퓨터 안에 여러대의 서버가 있을 수 있다. 클라이언트가 접속했을 때 그 중의 어떤 서버와 통신해야 할 지 정한다.
우리는 3000번 포트에 있는 서버와 통신한다.
3000번 포트에 우리의 Node.js 웹서버를 실행시킨 것이다.
if port = 80이라고 해보자.이때는 포트번호는 지정해주지 않아도 된다.웹서버는 굉장히 유명한 서버기 때문에 웹서버는 80번 포트를 쓴다 라고 전세계적으로 약속되어 있기 때문만약 우리가 http를 통해 접속 했다 -> 웹서버에 접속한 것이기 때문에 포트번호를 접속하면 자동으로 80번 포트와 통신
4) path : 파일어떤 파일인지를 가리킨다.
5) Query string : 쿼리 스트링
쿼리 스트링의 값을 변경하면 웹서버에게 어떤 데이터를 전달할 수 있다. ex) (?id=HTML&page=12) : 내가 읽고 싶은 정보는 HTML이고 12페이지다.
쿼리스트링의 시작은 ?로 하기로 약속했다.
값과 값은 &로 구분한다.
값의 이름과 값은 =로 구분한다.
URL을 통해서 입력된 값 사용하기
이미지 참조 : 생활코딩 Egoing Node.js 강의 (https://opentutorials.org/module/3549/21046)위 주소로 사용자가 웹 애플리케이션에 접속을 했을 때 우리가 해야할 일은 저 ID값이 무엇이냐에 따라서 사용자에게 적당한 컨텐츠를 보여주는 것이다.
Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications.Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.
<img src="coding.jpg" width="100%">
</p><p style="margin-top:45px;">HTML elements are the building blocks of HTML pages. With HTML constructs, images and other objects, such as interactive forms, may be embedded into the rendered page. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. HTML elements are delineated by tags, written using angle brackets.
Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications.Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.
<img src="coding.jpg" width="100%">
</p><p style="margin-top:45px;">HTML elements are the building blocks of HTML pages. With HTML constructs, images and other objects, such as interactive forms, may be embedded into the rendered page. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. HTML elements are delineated by tags, written using angle brackets.