Monday 10 April 2017

Question about streams and accessing file content

I'm trying to create an Excel worksheet with Node.JS and be able to upload it to Dropbox using their API. This is how I create the Excel spreadsheet.const Excel = require('exceljs') const workbook = new Excel.Workbook() workbook.addWorksheet('My Worksheet') const myWorksheet = workbook.getWorksheet('My Worksheet') myWorksheet.columns = [ { header: 'Name', key: 'name', width: 32 } ] myWorksheet.addRow({ name: 'John Doe' }) workbook.xlsx.writeFile('my_worksheet.xlsx') .then(() => { console.log('Worksheet created successfully') }) This works great, but I don't want to save it to a file. I would like to know a way to save the contents of the file in a variable/stream? (I'm a beginner at node). The ExcelJS docs mention something about using streams but didn't say anything about accessing the file content.This is how I upload a document using Dropbox's API.const Dropbox = require('dropbox') const fs = require('fs') const dbx = new Dropbox({ accessToken: '' }) fs.readFile('./test.txt', 'utf8', (err, contents) => { if (err) console.log(err) dbx.filesUpload({ path: '/test.txt', contents: contents }) .then((response) => { console.log(response) }) .catch((err) => { console.log(err) }) }) Thank you.

Submitted April 11, 2017 at 03:37AM by 39103910319vbrhbvfb

No comments:

Post a Comment