> npm install ejs
1. server.js
//모듈 추출
var http = require('http');
var fs = require('fs');
var ejs = require('ejs');
//서버 생성 및 실행
http.createServer(function(request, response){
// EJSPage.js 파일 로드
fs.readFile('index.ejs', 'utf8', function(error, data){
response.writeHead(200, {'Content-Type':'text/html'});
response.end(ejs.render(data, {
title:'EJS Example',
sub:'Multiplication'
}));
});
}).listen(3000, function(){
console.log('Server Running at http://127.0.0.1:3000');
});
2. index.ejs
<% var num = 2 %>
<h1><%= title %></h1>
<h2><%= sub %> x <%= num %></h2>
<% for(var i=1; i<10; i++) { %>
<p><%= num %> X <%= i %> = <%= num* i %><p>
<% } %>
'프로그래밍 > nodeJS' 카테고리의 다른 글
| [nodeJS] connect / connect_router 모듈 (0) | 2015.01.27 |
|---|---|
| [nodeJS] jade 모듈 (0) | 2015.01.27 |
| [nodeJS] http 모듈 + FileSystem 모듈 (0) | 2014.12.29 |
| [nodeJS] hello world (0) | 2014.12.29 |
| [nodeJS] nodeJS 란? (0) | 2014.12.29 |