一、path
1、basename() 文件名+后缀名
2、dirname() 路径名
3、extname() 后缀名
4、parse() 将路径解析成对象
5、join() 拼接路径
6、format() 将对象整合成路径字符串
7、isAbsolute() 是否是一个绝对路径
const path = require("path");
let filmPath = __dirname + '/db/film.json';
console.log(path.basename(filmPath));
console.log(path.dirname(filmPath))
console.log(path.extname(filmPath))
console.log(path.join("/a","/b/c","../d"))
console.log(path.parse(filmPath))
console.log(path.format({
root: 'C:/',
dir: 'C://users/leo/day03/ok',
base: 'index.html',
ext: '.html',
name: 'index'
}))
console.log(path.isAbsolute(p))
二、http
1、创建web服务器,将普通电脑编程web服务器;
2、前言
●IP地址:每一台计算机在互联网的地址唯一,点分十进制 192.168.0.1,在终端通过ping+网址可查看ip,127.0.0.1是自己电脑的可访问地址(localhost);
●域名:比如姓名与身份证号
●端口号:一台电脑可以开启多个web服务,但是每个web服务对应唯一端口,80端口可省略不写
3、第一个http服务
var http = require('http');
http.createServer(function (request, response) {
// 发送HTTP头部
// HTTP状态值:200 :OK
// 内容类型:text/plain
response.writeHead(200, {"content-type":"text/html;charset=utf-8"});
console.log("hello world");
// 发送响应数据“hello world”
response.end('hello world\n');
}).listen(8888);
4、可根据req.url来区分请求状态
三、url
const {URL} = require('url');
let url = 'http://192.168.0.3:3000/soul/users/hb/sjz/xh.json?sex=1&age=[18,26]';
let myurl = new URL(url);
console.log(myurl);
请求结果: