Run yarn command in a different directory, and starting up 2 servers with node/yarn

If you would like to run a yarn command from another directory you can use –cwd.

yarn --cwd <path> <yarn command>

An example for starting the client from the /client path would be yarn --cwd client start

This is super helpful when trying to start a server and client side app concurrently.

Install the concurrently npm.

And in your scripts file in the package.json add:

  "scripts": {
    "server": "nodemon index.js",
    "client": "yarn --cwd client start",
    "start": "concurrently \"yarn server\" \"yarn client\""
  },

 

Now yarn start will start up both servers in a single terminal with one command!

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner