SDK - How to use the serializeToJs() function?

I have heard about the serializeToJs function ( This is a description to get information about the code to generate parts of the domain model. How can I use the serializeToJs function to get the code to create my whole Mendix App? Especially I am interested to see, how to create pages.
1 answers

I am not sure if it is possible to generate source code for the entire project. However, you can pass the required model unit(microflow, pages, etc..) to serializeToJs() method that generates the source code for the same.


The below code snippet generates source code for the microflow. You can try retrieving the page model unit and give a try.


async function serializeToJs() {
    try {
        const client = new MendixPlatformClient();
        const moduleName = "MyFirstModule";
        const mfName = "IVK_TestSDKFlow";
        const app = client.getApp("YOUR-APP-ID");
        const workingCopy = await app.createTemporaryWorkingCopy("trunk");
        const model = await workingCopy.openModel();

        const module = model.findModuleByQualifiedName(moduleName);

        const domainModelInterface = model
            .filter((dm) => === moduleName)[0];

        const domainModel = await domainModelInterface.load();

        const mfInterface = model
            .filter((mf) => mf.qualifiedName === `${moduleName}.${mfName}`)[0];

        const mf = await mfInterface.load();

        // Redirect generated code to a file.
            (err) => {
                if (err) {
                    console.error(`Exception while writing to a file. ${err}`);

            `Domain model source code generation for the module ${moduleName} completed.`
    } catch (error) {
        console.log(`error: ${error}`);