简单后端接口的搭建

497 阅读1分钟

详细说明:见此处

www.cnblogs.com/mq0036/p/52…

简单http接口搭建

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");

Express框架的核心是对http模块的再包装。上面的代码用Express改写如下。

var express = require('express');

var app = express(); app.get('/', function (req, res) { res.send('Hello world!'); });

app.listen(3000);