1.目录展示.
2.代码实现:
const fs = require('fs');//系统自带模块(无需下载)
const path = require('path');//系统自带获取路径拼接方法(无需下载)
const http = require('http');//(无需下载)
const app = http.createServer();//(创建服务器)
const url = require('url');//系统自带get请求路径操作方法(无需下载)
const mime = require('mime');// npm install mime(命令行中输入后下载 23行中解释使用)
app.on('request',(req,res) => {
//获取用户的请求路径
let pathname = url.parse(req.url).pathname;
pathname = pathname == '/' ? '/about.html' : pathname;
//将用户的请求路径转换为实际的硬盘绝对路径
let realPath = path.join(__dirname, '全橙模板' + pathname);
if(pathname == '/abc'){ //自定义设置url路径