Node.js知识总结(三)

一、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);

请求结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值