This tool provides a function that takes a Three.js scene and outputs a workable SDFormat file.
To use this tool in a Node project, do:
npm install ogoudey/sdf-export
And to import it:
import exportSDF from 'sdf-export';
And later:
const { sdf, meshFiles } = await exportSDF(scene);
Now you have the SDFormat file as a string, and a list of mesh blobs ready to write (the SDF references files with meshes/..., so that's where they should be written).