Multi-module Node.js App Development Can Be Fun, Quick and Safe

Ido Amram
Wix Engineering
Published in
3 min readMay 8, 2022

This article will save your day if

  • Your Node.js app is spread across two or more isolated modules/libraries
  • You have cross-module features

Why multi-module?

As your app gets bigger with more and more developers working on it, splitting the app into smaller pieces of code (modules/libraries) can help your team maintain the flexibility and velocity they were used to while working on a smaller code base.

The Challenge

Modules are part of a single app and typically depend on each other. Hence, a change in one module typically affects other modules.
While developing a module locally can be fairly straightforward, pushing your changes to the actual app where the module is used is not a trivial task.

And that is the (pain) point

How can you be sure that a feature you’ve been working on works well with all the relevant modules when you’re done in your development environment?
If you can’t be sure — it means you’ll spend a lot of time making sure your feature is ready to be delivered.

Let’s look at an example

We have two modules:

- Lib
— package.json
— node_modules

- App
—Package.json
—node_modules

The App module has a dependency on Lib. Now, for a feature we’re developing in App, we need to make changes in Lib.

There are two options:

  1. Apply and check your changes after deploying
    develop a feature → build the app → QA → find bugs → fix them → build → QA → if all is good, we’re done, if not → start the cycle again.
    In this method we make changes in one module and hope it will work fine and that the tests for our app will pass. We need to build our application with the relevant changes to test the integration.
  2. Apply and check your changes while coding
    run App → go to MyApp/node_modules/Lib/myLib.js and make the changes there, while you can see the integration live.
    Since node_modules are not tracked by Git, we have to remember exactly what we changed and sync our changes manually from App/node_modules/Lib/myLib.js to Lib/myLib.js so we could later commit them to git and publish.

Sounds familiar? These methods are time consuming and frustrating.

The solution

Develop the feature in Lib, under source control, and see your changes in the app before publishing — so that when we are done, we’ll just push all relevant modules to our source control and build our app.

  • No messy copy-paste
  • No need to hope for it to just work
  • Natural development process

Introducing Syncli

A CLI tool for syncing modules. Syncli is a tool for making multi-module app development more fast and safe. It allows you to work on a multi-module feature as if it was a single module by simply syncing two modules in your development environment.

Under the hood

Syncli uses watchman-make to observe file changes. When a change is detected, Syncli seamlessly syncs between the file that is being edited and the corresponding file under node_modules (or the given destination path) — using rsync.

How simple is it ?

From the Lib folder, we run Syncli with the path of the corresponding Lib inside App’s node_modules (../App/node_modules/Lib) → now any change we make in a file under Lib will be seamlessly synced to App/node_modules/Lib

Syncli is flexible

You can choose which files/folders will be watched or ignored, by name or file type. Don’t worry, it has great default configurations so you can focus on your work.

How we use it at Wix Mobile

First — how we work — in (very, very) short:
1. We use React Native
2. All native code and dependencies are in a project called “Engine”.
3. All other code is developed in JavaScript modules that are plugged into the “Engine” (For example, there are separate modules for Bookings, Stores, Chat, Blog, Forum, Notifications, etc.)

More in the depth — a great blog posts series by Omri Bruchim

Have you noticed the multi-module integration challenge?
That’s exactly why I created Syncli. We have cross-module features, and using Syncli makes developing a cross-module feature more safe and fast.

You’re welcome to help improve Syncli

It’s here to make the development of a multi-module app fun, quick and safe. If you have a suggestion or you find a missing feature — please feel free to open an issue/PR.

--

--

Ido Amram
Wix Engineering

Full-stack Mobile Developer | Team lead @ Wix | Entrepreneur