node筆記 二 fs模組

2021-09-13 03:06:12 字數 1119 閱讀 1159

var fs = require('fs');
檢測是檔案還是目錄

fs.stat('txt.txt',function(err,state)else

})

建立目錄

fs.mkdir('css',function(err)else

})

讀取檢視目錄

fs.readdir('html',function(err,data)else

})

[ 'css', 'js', 'news.html', 'style.css' ]
刪除目錄

fs.rmdir('css',function(err)else

})

建立並寫入檔案

fs.writefile('txt.txt','你好,node.js111','utf8',function(err)else

})

追加內容到檔案裡,可以一直追加

if(err)else

})讀取檢視檔案

重新命名或者剪下檔案

fs.rename('html/index.html','html/news.html',function(err)else

})

剪下前後對比

刪除檔案

fs.unlink('t.txt',function(err)else

})

Node系統模組 fs

node裡有乙個名詞,叫做 模組 英文叫做module。主要分為系統模組和自定義模組,自定義模組就涉及到npm了,以後再說這個工具。今天主要介紹一下系統模組裡面,用來操作檔案的module fs。node有乙個函式叫做require,它就是幫助你來引入模組的,具體使用以fs來舉例子 const fs...

node內建模組 FS

1 操作資料夾 mddir readdir,rename,rmdir const fs require fs 建立資料夾,不能建立重複的資料夾!fs.mkdir test err 更改 fs.rename test test01 err else 刪除 只能刪除空資料夾 fs.rmdir node0...

node內建模組 fs

fs node內建模組 操作檔案 fs方法 讀取 刪除 寫 建立 fs方法 同步 和 非同步 fs api 操作檔案 讀取 寫 覆蓋式,追加式 刪除 判斷是否存在 let con fs.readfilesync path,utf 8 同步讀檔案 預設返回buffer,編碼格式指定utf 8 fs.r...