LoginSignup
4
3

More than 5 years have passed since last update.

app.router を明示的に use する意味

Last updated at Posted at 2014-09-28

app.use(app.router); を書かなくても動いたので、その意味を調べた。

app.js パターンA:

// ..略..
app.use(app.router);
app.use(express.errorHandler());
app.get('/', function(req, res, next){
  // '/' へのアクセスでわざとエラーになるようにする
  throw new Error();
});
// ..略..

app.js パターンB:

//app.use(app.router);  // コメントアウト
app.use(express.errorHandler());
app.get('/', function(req, res, next){
  throw new Error();
});

これらを実行すると、パターンA だけに errorHandler が適用されていた。

app.router を明示的に use しない場合は、最初の app.get (や post や all など) のときに暗黙的に app.router を記述したのと同じになる。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3