系统模块:http://nodejs.cn/api/events.html
自定义模块:
require 请求:引入模块
module 模块:批量输出
exports 输出:单独输出
express基础应用
// 下载express cnpm install express const express = require('express');
const static = require('express-static');
//1.创建服务 var server = express(); // 3.处理请求 // req,res与原生的是有区别的!! // 保留了原生的功能,增强了原有的功能(send) // 原生: // res.write(); 类型有局限性 // res.end(); // 添加的: // res.send(); 类似于write,但可以接收json server.use('/a.html',function(req,res){ res.send('abc'); //类似于res.write() res.end(); }); server.use('/b.html',function(req,res){ res.send('123'); res.end(); });
//get()接收get请求、post接收post请求、use接收所有请求 // server.get('/',function(req,res){ // console.log("有GET"); // }); // server.post('/',function(req,res){ // console.log("有POST"); // }); server.use('/',function(req,res){ console.log("USE了"); }); // 2.监听 server.listen(8081);
//配置打开文件的路径,设置静态文件目录
server.use(static('./section09/www'));