To -> 中文
Node.js -> fs: Simple use tool
npm i rxfile-write --save-dev
- Determine whether the
file
/directory
exists -
Read
everything in thefile
-
Erase
write content to file,oradd
content to a file -
Delete
file/directory
// 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