시나브로자바스크립트 - 웹서버기초(1,2)

null·2024년 1월 11일
0

시나브로

목록 보기
1/1

(1) 강의에서. .

1번.
웹서버 작성 코드를 작성하다가 Content-Type은 뭘까? 궁금해졌다.
res.setHeader('Content-Type', 'text/plain');

The Content-Type entity header is used to indicate the media type of the resource. In requests, (such as POST or PUT), the client tells the server what type of data is actually sent. (Source: MDN Web Docs)

HTTP GET 메소드는 text 형식으로 보내지니까 별도로 Content-Type 필요 없지만 POST, PUT처럼 request 하는 것은 필요해 ! 인용

즉 Content-Type은 request에 실어보내는 데이터(body)의 Type 정보라고 할 수 있다. 인용

2번.
package.json --> "type": "module" 이라면 import / export를 써야한다.

// 변경전
const http = require('http');

// 변경후
import http from 'http';

만약 변경하기 싫고. require로 할거라면 해당 .js 파일을 .cjs로 바꾸자.

(2)강의에서. .
node.js만 순수하게 쓴다면 간편하지만, 관리가 어려울 수 있어.
그래서 node.js 웹 프레임워크

profile
개발이 싫어.

0개의 댓글