Option One: Git
You don't specify the version control system you're using but I'll assume it's Git since that is by far the most popular.
When using Git, there's a way to "embed" repositories within one another so they can be used as-if the code is saved directly in the parent, but is really under it's wn version control. This is called git submodules and whilst it's a great solution, it's also quite complex and may be overkill for what you want.
Basically, you would go from a structure like this:
| - repo1
| - shared file
| - repo2
| - shared file
To this:
| - repo1
| - git submodule: repo3
| - repo2
| - git submodule: repo3
| - repo3
| - shared code
Option Two: NPM
Since you specified you're working with Javascript, you could also use the Javascript package manager; NPM. NPM allows you to "package" code up and then import it into other projects.
NPM is by far more popular than git submodules and learning how to use it will be a valuable skill if you intend to work with modern JS.
In this case, you would move the shared code to a new repo (as you would with Git submodules, above) and then package it and publish it.
Then, you can import this packaged code into your two existing repos.
NPM requires you to have NodeJS installed and that you have a build process in place to import the NPM package and pack everything up in a way your browser can handle it.
Check out the NPM getting started guide for more info.
Feel free to ask any questions in the comments ??
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…