// 常用node核心模块: fs、http、url、path、queryString

// 服务器运行环境
// 处理文件,连接数据库
// 高并发,用来做中间层

// http
// const http = require(‘http’)
// http.createServer((req, resp) => {
// resp.end(‘

hello

’)
// }).listen(8080, () => {
// console.log(‘port 8080 is listening’)
// })

// fs
// readFile writeFile appendFile unlink(unlink删除文件夹必须是空文件夹)
// 这些方法都是异步,但是每一个异步方法都有一个对应的同步方法,比如:readFileSync

// path
const path = require(‘path’)
// const str = ‘C://nz/code/index.js’
// // 解析成对象
// console.log(path.parse(str))

// const obj = {
// root: ‘D:/’,
// dir: ‘D://nz1908/code’,
// base: ‘index2.js’,
// ext: ‘.js’,
// name: ‘index2’
// }
// // 序列化路径字符串
// console.log(path.format(obj))

// console.log(path.join(‘nz/code/node’, ‘…/index.js’))
// // __dirname 全局魔术变量:无论在哪里都可以直接使用,代表当前路径
// console.log(__dirname)

// // 从当前位置触发利用相对路径最终得到绝对路径
// console.log(path.join(__dirname, ‘…/README.md’))

// ‘nz/code/node’ + ‘…/index.js’

// url
// const url = require(‘url’)

// const baidu = ‘http://www.baidu.com/pic/icon/index.html?id=3&from=index#top’
// console.log(url.parse(baidu))

// const obj = {
// protocol: ‘http:’,
// slashes: true,
// auth: null,
// host: ‘www.baidu.com’,
// port: null,
// hostname: ‘www.baidu.com’,
// hash: ‘#top’,
// search: ‘?id=3&from=index’,
// query: ‘id=3&from=index’,
// pathname: ‘/pic/icon/index.html’,
// path: ‘/pic/icon/index.html?id=3&from=index’,
// href: ‘http://www.baidu.com/pic/icon/index.html?id=3&from=index#top’
// }
// console.log(url.format(obj))

// const qs = require(‘querystring’)
// const str = ‘id=3&from=index&type=1’
// console.log(qs.parse(str))

// 默认是按照&和=分割,也可以指定分隔符
// const str = ‘id,3;from,index;type,1’
// console.log(qs.parse(str, ‘;’, ‘,’))

// const obj = {
// name: ‘zhangsan’,
// age: 18,
// gender: ‘男’
// }

// // console.log(qs.stringify(obj))
// console.log(qs.stringify(obj, ‘%’, ‘-’))

// console.log(qs.escape(‘逆战’))
// console.log(qs.unescape(’%E9%80%86%E6%88%98’))

//crytpo
const crypto = require(‘crypto’)
// 这个算法只能加密不能解密,所以我们可以把两次的加密结果判断是否相等来决定原文是否相等
// 加密算法需要的密钥,不同的密钥加密同一个文本结果不一样的
const secret = ‘dfdsvfdgd’
const hash = crypto.createHmac(‘sha256’, secret).update(‘I love cupcakes’).digest(‘hex’);
console.log(hash)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值