如何处理Express.js中的路由

时间:2013-09-23 10:04:13

标签: express

如何处理Express.js中的路由以及有多少方法可以通过代码和demo.answer通知我,谢谢。谢谢

1 个答案:

答案 0 :(得分:2)

我写过a longer guide that explains this stuff,但这是一个简单的例子:

var express = require("express");

var app = express();

app.get("/", function(request, response) {
  response.send("Welcome to the homepage!");
});

app.get("/about", function(request, response) {
  response.send("Welcome to the about page!");
});

app.get("*", function(request, response) {
  response.send("404!");
});

app.listen(1337);