参考URL→http://hideyukisaito.com/doc/expressjs/guide/
- コード
var app = require('express').createServer(); app.get('/users/:id?', function(req, res, next){ var id = req.params.id; if (id) { res.send("ユーザID:" + id); }else{ next(); // ユーザIDがなければ「なし」用画面へ } }); app.get('/users', function(req, res){ res.send("ユーザIDなし"); }); app.listen(3000);
- 実行結果1 (ユーザID指定)
- 実行結果2 (ユーザID未指定)
このページへのコメント
TIisNT <a href="http://itecuhsvyshe.com/">itecuhsvyshe</a>, [url=http://acsluoeechpm.com/]acsluoeechpm[/url], [link=http://ujycwyysxmsk.com/]ujycwyysxmsk[/link], http://xtxfozujhswx.com/