Skip to content

Instantly share code, notes, and snippets.

@edom18
Created November 12, 2011 07:00
Show Gist options
  • Save edom18/1360172 to your computer and use it in GitHub Desktop.
Save edom18/1360172 to your computer and use it in GitHub Desktop.
example express
/**
* 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);
<!-- views/index.ejs -->
<article>
<section>
<header><h1>見出し</h1></header>
<p><%= test %>テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。テスト文章。</p>
</section>
</article>
<!-- views/layout.ejs -->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= title %></title>
</head>
<body>
<%- body %>
</body>
</html>
<!-- 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