Is there a way to run prosemirror on nodejs?

I use promirror-collab module & store prosemirror changes. Because of some reason, I want to fetch the latest state of my document in nodejs environment. But since the base document & changes are stored separately in different formats, can’t find a simple way to do it.

Most of the ProseMirror modules work in node.js—notably prosemirror-model and prosemirror-transform—so creating and manipulating documents there shouldn’t be a problem.

Here’s a slightly abbreviated version of how we run it server side for an import script

const jsdom = require('jsdom')
const { JSDOM } = jsdom
const {DOMParser} = require('prosemirror-model')
const {bodySchema} = require('../../app/javascript/lib/schema/index.js')
const parser = DOMParser.fromSchema(bodySchema)

...

  const dom = new JSDOM(someHTMLString)
  const jsonSerializable = parser.parse(dom.window.document, { preserveWhitespace: true }).toJSON()

We load the document from JSON (on node by calling Node.fromJSON) and it works like a charm. @jabberthonky What is the point where you got stuck?

what about prosemirror-view or should I ask which modules don’t work with node?

ProseMirror view should require dom access afaik - but you shouldn’t need it (model/state etc have all you need).

Could you post the expected output and the actual output of your code? I am still not sure I understand where you are stuck.

Hi, Sorry for the delayed response. Actually, I want to apply receiveTransction on nodejs. Will it be possible to do that? I see that to apply transaction one needs to dispatch through view Use case is that I want to call .toJSON() & get the document

You don’t need a view to work with transactions. In fact, nothing in the prosemirror-collab module depends on prosemirror-view. Transactions can be applied directly to a state, outside of any view logic.