Node.js 강좌 자료] ejs 모듈
Node.js 강좌 자료] ejs 모듈
실무개발자를위한 실무교육 전문교육센터학원
www.oraclejava.co.kr에 오시면 보다 다양한 강좌를 보실 수 있습니다.
ejs 모듈
- 웹 애플리케이션에서 사용되는 HTML을 생산하는 템플릿 엔진
- HTML을 기반으로 동적 실행 코드를 삽입하는 구조의 페이지 사용
- jsp, php, asp 등의 페이지 구문과 유사한 형태
- 예제
» ejs 페이지
:
<h1><%= name %></h1>
<p><%= description %></p>
<hr />
<% for(var i = 0; i < 10; i++) { %>
<h2>The Square of <%= i %> is <%= i * i %></h2>
<% } %>
const http = require('http')
const fs = require('fs')
const ejs = require('ejs')
const server = http.createServer(handler)
server.listen(8081)
function handler(req, res) {
fs.readFile('ejs-module.ejs', 'utf8', (err, data) => {
res.writeHead(200, {'Content-Type':'text/html'})
res.end(ejs.render(data, {
name: 'John Doe',
description: 'Hello ejs with Node.js'}))
})
}
'자바' 카테고리의 다른 글
Node.js 강좌 자료] 서버 실행 관리 모듈 (0) | 2017.11.26 |
---|---|
Node.js 강좌 자료] jade(pug) 모듈 (0) | 2017.11.26 |
Node.js 강좌 자료] 웹 어플리케이션 아키텍처 (0) | 2017.11.26 |
Node.js 강좌 자료] 웹 애플리케이션 (0) | 2017.11.26 |
Node.js 강좌 자료] EventEmitter클래스의 예제 (0) | 2017.11.26 |