Leo Avramovic
Leo Avramovic

Reputation: 21

Add existing NodeJs (node, Express, monodb,...) project to existing a NX monorepo (Angular)

Has anyone experienced how to add an existing NodeJS API to an existing (Angular) Nx Monrepo?

Unfortunately the manual doesn´t help me so much https://nx.dev/migration/manual

Upvotes: 2

Views: 1952

Answers (2)

Ro Marcus Westin
Ro Marcus Westin

Reputation: 29660

Here is a solution that I wrote and used to import multiple repos into a single monorepo, under whatever subdirectories are wanted, while maintaining commit history:

I've also found two other scripts that look like they might work, but I haven't tried them:

Upvotes: 2

The Fabio
The Fabio

Reputation: 6250

The process of migrating a repo into your mono repo requires a few manual steps. I think there would not be a simpler way to do it.

Assuming your node project does not share files with your current monorepo, this should be the steps:

  1. on your node repo, create a branch 'to-monorepo' and in it, move all the files to folders that match the nx folder structure and push the commits to it.
  2. remove your package.json file (we will later merge it with the monorepo's one)
  3. once the folders match the nx folder structure, time to merge into the monorepo. From the monorepo add the remote of the other repo
git remote add node-repo <your git repo's node url>
  1. at the monorepo folder, checkout your master
  2. run a pull to make the node repo branches be available in the monorepo
git pull
  1. create a new branch 'merging-node-repo' on your monorepo.

  2. merge the branch node-repo/to-monorepo into your merging-node-repo branch, preserving the history:

git merge node-repo/to-monorepo --allow-unrelated-histories
  1. push your new branch (all the code and its history will now be listed in this new branch)

  2. remove the remote node-repo from your local monorepo configs

git remote rm node-repo
  1. manually merge all the node repo's original package.json file dependencies into the monorepo's one, and run npm install from the monorepo. This way your package-lock.json file is updated. Once you are done, create a commit and push it.

  2. this last step is more tricky. You have now to manually update the monorepo's config files to allow nx to start managing it. This is where the link you had in your question might help. Once you are done, create a commit and push it.

With these steps you can then merge your merging-node-repo branch into master.

I recommend you to create a separated nx workspace with a nodejs project on it. This helps you with having a baseline for all the necessary nx configurations and dependencies. You might want to make sure your project works via nx commands from this separated workspace; this way you will have a better chance of getting configurations of your monorepo right.

Hopefully this gets you started.

Upvotes: 2

Related Questions