Write Observable content into a file (overwriting its contents)
import path from'path';import {of} from'rxjs';import {writeFile} from'rxfs';constdata= ['"animal","coolness"\n','"dolphin",10\n','"algae",1\n','"mermaid",6\n','"octopus",9\n','"narwhale",8\n',];constwriteStream$=of(...data).pipe(writeFile({filePath:path.resolve(__dirname,'./output.csv')}));// write the input observable to the filewriteStream$.subscribe(console.log);
Append Observable content to a file
import path from'path';import {of} from'rxjs';import {appendFile} from'rxfs';constmoreData= ['"barnacle",3\n','"seagull",2\n','"clownfish",4\n',];constwriteStream$=of(...moreData).pipe(appendFile({filePath:path.resolve(__dirname,'./output.csv')}));// append the input observable to the filewriteStream$.subscribe(console.log);