전 포스팅에서 서버에서 일일히 url을 설정하지 않기 위해 express.js에 대해 알아보겠다. http://expressjs.com/ Express - Node.js web application framework Fast, unopinionated, minimalist web framework for Node.js $ npm install express --save expressjs.com express는 Node.js를 위한 웹 프레임 워크이다. express에는 어플리케이션 미들웨어 라우터 request response 등의 개념이 있다. 어플리케이션은 익스프레스 인스턴스를 의미한다. 우선은 express를 설치하자 npm install express --save index.js 파일을 (http..
우선은 terminal을 하나 더 열고 curl -X GET "localhost:3000" 를 실행해보면 Hello World가 찍힐 것이다. 서버가 listen의 대기상태이고 요청이 들어올 때 마다 해당 서버 코드의 콜백함수가 동작하는 것이다. const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader("Content-Type", "text/plain"); res.end("Hello World"); }); 이때 아래를 실행해도 Hello World가 찍힐 것이다. 그렇다면 /intro는 어디에 있는 것일까? curl -X GET "localhost:3000/intro" 정답은 저 곳의 req에 있다. req.u..
https://nodejs.org/en/docs/guides/getting-started-guide/ Getting Started Guide | Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org 를 살펴보자. index.js파일을 만들고 코드를 작성해보자. 다음 node index.js를 terminal에서 실행해주면 127.0.0.1, port는 3000에서 Hello World를 찍어준다. 코드를 간단히 살펴보면 http 모듈을 불러오고. hostname 과 port를 지정해주었다. 다음은 http모듈의 createServer method를 활용하여 Server를 만들었다. 마지막으로 s..
