router.get is only for defining subpaths. Consider this example:
var router = express.Router();
app.use('/first', router); // Mount the router as middleware at path /first
router.get('/sud', smaller);
router.get('/user', bigger);
- If you open /first/sud, then the
smallerfunction will get called. - If you open /first/user, then the
biggerfunction will get called.
In short, app.use('/first', router) mounts the middleware at path /first, then router.get sets the subpath accordingly.
But if we instead use the following:
app.use('/first', fun);
app.get('/sud', bigger);
app.get('/user', smaller);
- If you open /first in your browser,
funwill get called, - For /sud,
biggerwill get called - For /user,
smallerwill get called
But remember for /first/sud, no function will get called.
This link may also help: http://expressjs.com/api.html#router