기본적으로 설치는 npm을 통해 이루어진다. 가급적이면 함께 따라다니는 jade도 함께 설치해 두는 편이 좋다.
npm install express jade실제 서버에서는 코드와 분리해서 (광역)설치하는 편이 좋을 것 같다.
npm install -g express jade
Express로 웹서버를 구축하는데 가장 기본적인 코드는 다음과 같다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express.createServer(); | |
app.get('/', function(req, res){ | |
res.send('Hello World'); | |
}); | |
app.listen(3000); |
이 코드를 실행시킨 후 브라우저로 http://localhost:3000/ 으로 접속해 보면 Hello World가 표시되는 것을 확인할 수 있다.
Express의 코드는 Node.JS의 서버 시작 코드보다 훨신 단순하면서도 가독성은 좋은 것 같다.
0 comments:
댓글 쓰기