Using firepad with node.js

663 Views Asked by At

How would I modify the text in a firepad editor on my webpage using Node? What I'm trying to do is have the user upload a file, then read the contents of the file, and replace the firepad contents with the uploaded file's contents.

I see that there's a firepad npm module https://www.npmjs.com/package/firepad, but it doesn't say how to use it with node. I currently have it setup in my html and using a normal public js file in my node project.

So I was thinking that to update the text, I could either send a post request with the text, and my client side js would receive it and then update the firepad since it has access to the firepad variable there.

Or I could use the npm module, but I'm not sure if it's a full module.

2

There are 2 best solutions below

4
On BEST ANSWER

Take a look at the Firepad Headless docs. Here's an example:

var Firepad  = require('firepad')
var firepadRef = ... // create firebase database reference to your firepad data.
var headless = new Firepad.Headless(firepadRef)

headless.setText('Welcome to Firepad!', function(err, committed) {
  // *err*       will be set if there was a catastrophic failure
  // *committed* will be true on success, or false if there was a history
  //               conflict writing to the pad's history.
});
0
On

A workaround till the available npm version (1.4.0) gets the patch is to define window:

   global.window={};
   const Firepad = require('firepad');