블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2012. 12. 15. 14:17 NodeJS/Concept

EJS (Embedded JavaScript) 엔진은 자바쪽의 JSP 사용과 거의 유사하다고 보면 된다. 


  • 장점 : JSP 코딩처럼 쉽게 적응할 수 있다
  • 단점 : 프레임워크가 무거움 

> young.js : express를 사용할 것이고, 기본적으로 views 폴더 에 위치한다
var express = require('express');
var ejs = require('ejs');
var app = express();

app.get('/', function(req, res) {
res.format({
html: function() { res.send('<h1> hi dowon in html</h1>');},
json: function() { res.send({message: 'hi dowon in json'});},
text: function() { res.send('hi dowon in text');}
});
});

// response.send에서 response.render로 바뀌는 것 뿐이다 
app.get('/young/:id', function(req, res) {
res.render('young.ejs', {youngMessage: 'I am ' + req.params.id, layout: false});
});


> young.ejs : html 태그는 제외했음

<%= youngMessage %>


ejs 보다는 jade를 사용하자 

'NodeJS > Concept' 카테고리의 다른 글

[Node.js] 생태계에 대한 생각들  (0) 2012.12.23
[Jade] Jade 사용하기  (0) 2012.12.15
[Node.js] Global Objects  (0) 2012.12.10
[Node.js] File I/O 사용하기  (0) 2012.12.10
[Node.js] EventEmitter 에 대하여  (0) 2012.12.10
posted by 윤영식