Export scene from main.js file and import in other module js file

I am new to three.js and as well as javascript.
can we export scene object and import it in another js module file.
and if yes how can i do that?
is there any example regarding this?

You can export a scene by calling:

const json = scene.toJSON();

If necessary, you can then convert the JSON into a string by using JSON.stringify( json ). The string can be converted back by using JSON.parse(). The resulting object can be transformed to a three.js scene by using ObjectLoader.parse(). Check out the following demo that shows a complete round-trip:


Instead of using the three.js JSON format, you can also consider to use a 3D format like glTF to export and import objects.

ohk. thanks for your help.
can we do like this.

can we export scene, camera, controls etc. from “main.js” file where all three.js work is done.

export { scene, camera, controls }

and import to other “viewerFunction.js” module file to use camera and controls to do other work like changing camera position.

import {scene, camera, controls} from “/main.js”

Reason behind this I have to cut my code from "main.js " and put it into another js file according to some function.