node.jsfirebasefirepad

Using firepad with node.js


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.


Solution

  • 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.
    });