码迷,mamicode.com
首页 > 其他好文 > 详细

express再学习

时间:2016-08-27 19:16:36      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

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

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

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

技术分享

练习代码:

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再学习

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5813515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!