yarn a simple demo
1. Create a new folder
mkdir ~/test
2. cd into the working directory
cd ~/test
3. Create a package.json
vi ~/test/package.json
4. Add the following code
{
"private":true,
"workspaces": ["client", "server"]
}
5. Next create two folders within the test folder called client & server these will represent our own packages
mkdir ~/test/client
mkdir ~/test/server
6. Run yarn init within each folder and hit enter to initialize with all of the defaults
~/test/client yarn init
~/test/server yarn init
7. So now we have two projects client and server. We want to make one dependent on the other.
8. Within the server folder create a new file called server.js and add the following code
module.exports = () => {
console.log('hello from console');
}
9. Next create a new file within the client folder called client.js and add the following code
const commonFunction = require("common");
commonFunction();
10. To tell the client that the server exists we add dependency in the package.json in the client folder like below
"dependencies": {
"server": "1.0.0"
}
11. Next we run yarn install within the client folder to install dependencies
12 And if we go back to the root folder a new folder has been created called node_module
13. Next if we run client/client.js we should see the output and if we change server.js the output for the client will also change. This proves that the two folders have been symlinked.