Created
November 12, 2011 07:00
-
-
Save edom18/1360172 to your computer and use it in GitHub Desktop.
example 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
/** | |
* require module(express, ejs) | |
* @author edo | |
*/ | |
var express = require('express'), | |
app = express.createServer( | |
express.bodyParser() | |
, express.cookieParser() | |
, express.static(__dirname + '/public') | |
); | |
app.configure(function () { | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'ejs'); | |
}); | |
/** | |
* Routing | |
*/ | |
app.get('/', function (req, res) { | |
res.render('index', { | |
title: 'hogehoge', | |
test: 'test' | |
}); | |
}); | |
app.get('/user/:id', function (req, res) { | |
var id = req.params.id; | |
res.render('user', { | |
title: 'user', | |
id: id | |
}); | |
}); | |
app.listen(8881); |
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
<!-- views/index.ejs --> | |
<article> | |
<section> | |
<header><h1>見出し</h1></header> | |
<p><%= test %>テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。</p> | |
</section> | |
</article> |
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
<!-- views/layout.ejs --> | |
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title><%= title %></title> | |
</head> | |
<body> | |
<%- body %> | |
</body> | |
</html> |
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
<!-- views/user.ejs --> | |
<article> | |
<section> | |
<header><h1>ユーザーページ</h1></header> | |
<p>あなたのIDは「<%= id %>」です。</p> | |
</section> | |
</article> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment