一、路由:

index.js
~~~
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get('/helloworld', function(req, res, next) {
res.render('helloworld', {});
});
module.exports = router;
~~~
user.js
~~~
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
~~~
如果在瀏覽器中訪問localhost:3000,index.js中以下方法會響應
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
如果在瀏覽器中訪問localhost:3000/helloworld,index.js中以下方法會響應
router.get('/helloworld', function(req, res, next) {
res.render('helloworld', {});
});
如果在瀏覽器中訪問localhost:3000/users,user.js中以下方法會響應
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
如果是post請求,
router.post();
二、靜態資源
app.js中以下代碼負責配置靜態資源,代表靜態資源在public
~~~
app.use(express.static(path.join(__dirname, 'public')));
~~~

訪問靜態資源路徑如下:
http://localhost:3000/html/helloword.html
http://localhost:3000/stylesheets/style.css
在路由中跳轉靜態頁面:
~~~
router.get('/helloworld', function(req, res, next) {
res.redirect("html/helloworld.html");
});
~~~