Thursday 1 June 2017

Firebase write to file

I want write a file with a button event in index.html.

I installed the node-module file-system:

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
  "file-system": "^2.2.2",
  "firebase-admin": "~4.2.1",
  "firebase-functions": "^0.5.7"
},
"private": true
}

And I tried these two ways of require

index.js

var functions = require('file-system');
var fs = require('fs');

And these two ways of write

var stream = fs.createWriteStream("./public/input.txt");
  stream.once('open', function(fd) {
  stream.write("My first row\n");
  stream.write("My second row\n");
  stream.end();
});

fs.writeFile ( './public/input.txt', 'My first text!', function (err) 
{
   if (err) {
       return console.error (err);
   }
});

But, it only deletes the contents of the input.txt. Any better way to do this?



via Gurigraphics

No comments:

Post a Comment