|
/* Callback :( */ |
|
const doThing = () => |
|
fs.readFile('codes.json', 'utf-8', (err, data) => { |
|
if(err) throw err |
|
const newdata = data.replace(/1/g, '2') |
|
fs.writeFile('file2.json', newdata, (err, _) => { |
|
if(err) throw err |
|
console.log('success!') |
|
} |
|
} |
|
|
|
/* Using future :D */ |
|
const readFile = futurize(fs.readFile) |
|
const writeFile = futurize(fs.writefile) |
|
|
|
const doThing = () => |
|
readFile('codes.json') |
|
.map(data => data.replace('/1/g', '2') |
|
.chain(replaced => |
|
writeFile('codes2.json', replaced)) |
|
|
|
doThing().fork(e => console.log(e), |
|
r => console.log('success')) |