express再学习

对比spring,django,再学习express就有很多共通的地方啦。。。

看的书是一本小书,《express in action》,排版比较好。

昨天开始看,看了快四分之一啦。。。

express再学习

练习代码:

var express = require("express");
var http = require("http");
var path = require("path");
var logger = require("morgan");

var app = express();
var publicPath = path.resolve(__dirname, "public");

app.set("views", path.resolve(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static(publicPath));
app.use(logger("short"));

app.get("/", function(request, response) {
    response.render("index", {
        message: "Hey everyone! This is my webpage."
    });
});

app.get("/about", function(request, response) {
    response.end("Welcome to my aboutpage!");
});

app.get("/weather", function(request, response) {
    response.end("The current weather is NICE!");
});

app.get("/user/:who", function(request, response) {
    response.end("Hello, " + request.params.who + ".");
});

app.use(function(request, response) {
    response.statusCode = 404;
    response.end("404!");
});

http.createServer(app).listen(3000);

express再学习

上一篇:Node.js:模块


下一篇:搭建一个HTTP环境