Is it possible to create a JSON file from Cloud Function and save it to Cloud Storage? Answer: Yes if so How do we achieve that? Answer: Using dataStream.pipe see below an example
dataStream.pipe example:
var myJSON = JSON.stringify(Row);
const stream = require('stream'),
dataStream = new stream.PassThrough(),
gcFile = bucket.file("Leaderboard/users.json");
dataStream.push(myJSON);
dataStream.push(null);
await new Promise((resolve, reject) => {
dataStream.pipe(gcFile.createWriteStream({
resumable : false,
validation : false,
metadata : {'Cache-Control': 'public, max-age=31536000'}
}))
.on('error', (error) => {
reject(error)
})
.on('finish', () => {
resolve(true)
})
})
Thanks,