To -> EN
Node.js -> fs: 简单使用工具
npm i rxfile-write --save-dev
- 确定
文件
/目录
是否存在 - 阅读
文件
中的所有内容 擦除
将内容写入文件, 或 将内容添加
到文件- 删除
文件
/目录
// node / cjs
const RxfileWrite = require('rxfile-write')
// or
import RxfileWrite from 'rxfile-write'
const path = require('path')
function ps (p) {
return path.resolve(__dirname, '..', p)
}
// - - RxfileWrite.read 读内容- -
RxfileWrite.read(ps('LICENSE')).then(data => {
console.log('data\n\n', data)
}).catch(err => {
console.log('read error=', err)
})
// - - RxfileWrite.exists 判断是否存在- -
RxfileWrite.exists(ps('LICENSE')).then(() => {
console.log('exists is ok')
}).catch(err => {
console.log('exists error=', err)
})
// - - RxfileWrite.write 写 - -
RxfileWrite.write(ps('ttt.txt'), 'hello world!').then(() => {
console.log('write succ')
setTimeout(() => {
// - - RxfileWrite.remove 删除 - -
RxfileWrite.remove(ps('ttt.txt')).then(() => {
console.log('remove succ')
}).catch(err => {
console.log('remove error=', err)
})
}, 5000);
}).catch(err => {
console.log('write error=', err)
})
- exists
- read
- cp
- cpSync
- write
- writeSync
- writeAppend
- writeAppendSync
- writeTo
- remove