1. express是什么:
基于node.js平台开发的WEB开发框架, 就是一个node.js模块
2. express的作用:
它提供了一系列强大的特性, 帮助创建各种Web和移动设备应用
3. express的特点:
实现了路由功能
中间件(函数)功能
对request和response对象的扩展
可以集成其他模板引擎
4. express基本使用:
安装:
npm install express --save
使用:
// 加载 express 模块
var express = require('express');
// 创建一个 app 对象
var app = express();
// 通过中间件监听指定的路由的请求
app.get('/hello', function(req, res) {
// res.end('Hello,World!');
res.send('Hello,World!');
});
// 启动服务
app.listen(7777, function() {
console.log('http://localhost:7777');
});
5. res.end() 和 res.send() 的区别
参数区别:
res.end()参数只能是Buffer或者是字符串
res.send()参数可以是Buffer, Object, String, Array
res.send()会默认自动生成一些响应报文头, 其中包括 Content-Type: text/html; charset=utf-8