• hello world的一千种写法


    var http = require("http");
    
    var app = http.createServer(function(request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello world!");
    });
    
    app.listen(3000, "localhost");
    
    
    var express = require('express');
    var app = express();
    
    app.get('/', function (req, res) {
      res.send('Hello world!');
    });
    
    app.listen(3000);
    
    
    var express = require("express");
    var http = require("http");
    
    var app = express();
    
    app.use("/home", function(request, response, next) {
      response.writeHead(200, { "Content-Type": "text/plain" });
      response.end("Welcome to the homepage!
    ");
    });
    
    app.use("/about", function(request, response, next) {
      response.writeHead(200, { "Content-Type": "text/plain" });
      response.end("Welcome to the about page!
    ");
    });
    
    app.use(function(request, response) {
      response.writeHead(404, { "Content-Type": "text/plain" });
      response.end("404 error!
    ");
    });
    
    http.createServer(app).listen(1337);
    
    
    var express = require("express");
    var http = require("http");
    
    var app = express();
    
    app.use(function(request, response, next) {
      if (request.url == "/") {
        response.writeHead(200, { "Content-Type": "text/plain" });
        response.end("Welcome to the homepage!
    ");
      } else {
        next();
      }
    });
    
    app.use(function(request, response, next) {
      if (request.url == "/about") {
        response.writeHead(200, { "Content-Type": "text/plain" });
      } else {
        next();
      }
    });
    
    app.use(function(request, response) {
      response.writeHead(404, { "Content-Type": "text/plain" });
      response.end("404 error!
    ");
    });
    
    http.createServer(app).listen(1337);
    
    
    var express = require("express");
    var http = require("http");
    var app = express();
    
    app.all("*", function(request, response, next) {
      response.writeHead(200, { "Content-Type": "text/plain" });
      next();
    });
    
    app.get("/", function(request, response) {
      response.end("Welcome to the homepage!");
    });
    
    app.get("/about", function(request, response) {
      response.end("Welcome to the about page!");
    });
    
    app.get("*", function(request, response) {
      response.end("404!");
    });
    
    http.createServer(app).listen(1337);
    

    可以看出res.end方法需要设置响应头,而res.send则不用
    对应地res.sendfile及res.end(html)

    You can change the world with your heart,even a lot of changes sometimes unless you won't geiv up....
  • 相关阅读:
    J2SE-反射
    c3p0 连接数据库失败的问题
    c# 调用存储过程
    存储过程使用truncate时
    Parcelable intent传递对象时,需要将该对象实现Parcelable 或者Serializable
    android intent 在打开设置activity的时候在监听事件的内部 适用setclass()方法时 不是直接适用this 关键字
    c# 读取appconfig文件
    Oracle 连接数据库的几种方式
    通过反射获得方法,和绑定事件
    js 验证
  • 原文地址:https://www.cnblogs.com/xiongwei2017/p/6626640.html
Copyright © 2020-2023  润新知