no message

This commit is contained in:
chenxuan
2024-01-16 13:36:07 +08:00
parent ac3b4f30a8
commit ee741fd5c5
4 changed files with 87 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
const fs=require('fs')
console.group("-------readFile-------")
fs.readFile('./static/1.html','utf-8',function(err, dataStr){
// console.log(err.errno)
// console.log(err.code)
// console.log(err.syscall)
// console.log(err.path)
// console.log(!err ? "文件读取成功" : "文件读取失败")
// console.log(dataStr)
})
console.groupEnd()
console.group("-------writeFile-------")
fs.writeFile('./static/hehe.html','hello!','utf-8',function(err){
if(err){
console.log("文件写入失败")
return
}
console.log("文件写入成功!")
})
console.groupEnd()
console.group("-------appendFile-------")
fs.appendFile(__dirname+'/static/hehe.html',"vvvvvvvvvvvvvvvv",function(err){
if(err){
console.log("文件插入失败")
return
}
console.log("文件插入成功!")
})
console.groupEnd()
+43
View File
@@ -0,0 +1,43 @@
const path=require('path');
var testPath='f:code/node/chenxuan.js'
// 以获取路径中的最后一部分,经常通过这个方法获取路径中的文件名
console.group("------basename------")
console.log(path.basename(testPath))
console.log(path.basename(testPath,'.js'))
console.groupEnd()
// 获取路径中除文件名以外的路径
console.group("dirname")
console.log(path.dirname(testPath))
console.groupEnd()
console.group("------join------")
// __dirname 表示当前js文件所处的目录
// join 拼接路径
// '…/'会抵消掉一层路径
console.log(path.join(__dirname))
console.log(path.join(__dirname,'/hehe1','/hehehe2','/hehehe3'))
console.log(path.join(__dirname,'/hehe1','../','/hehehe3'))
console.groupEnd()
console.group("------parse------")
// parse 将路径格式化为对象
const mypath=path.join(__dirname,'/hehe1','/hehe2','/hehe3.html');
console.log(path.parse(mypath))
console.groupEnd()
console.group("------format------")
// format 将对象化的路径格式化为路径
const mypath1=path.join(__dirname,'/hehe1','/hehe2','/hehe3.html');
const objPath=path.parse(mypath1)
console.log(path.format(objPath))
console.groupEnd()
console.group("------extname------")
// 获取路径对象的扩展名
const mypath2=path.join(__dirname,'/hehe1','/hehe2','/hehe3.html');
const extname=path.extname(mypath2)
console.log(extname)
console.groupEnd()
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
hello!vvvvvvvvvvvvvvvv