0

Start multiple node servers with single command on windows operating system with help of batch file (.bat)

let's assume this is my folder structure with all microservices and all package.json have start, dev and test scripts defined.

project-root
|
+--auth-service
|   |
|   +--package.json
|
+--user-service
|   |
|   +--package.json
|
+--product-service
|   |
|   +--package.json
|
+--order-service
    |
    +--package.json

1 Answer 1

1

Save this file as run.bat on project-root directory

set type=%1

IF "%type%" EQU "install" (
    set command=npm install
) ELSE (
    set command=npm run %type%
)

IF "%type%" EQU "" (
    set command=npm run dev
)

start cmd /k "cd auth-service && %command% && exit"
start cmd /k "cd user-service && %command% && exit"
start cmd /k "cd product-service && %command% && exit"
start cmd /k "cd order-service && %command% && exit"

As you can see if no parameter passed services will run on dev mode.

From project-root directory open cmd and run command

To install all packages

run.bat install

To run in dev mode ( depends on dev script on respective package.json )

run.bat dev

To run in start mode ( depends on start script on respective package.json )

run.bat start

To run test mode ( depends on test script on respective package.json )

run.bat test

this will start a new cmd on respective directories and start executing given command... It is pretty handy when you need to start all services at once.

Note: Use this only for development stage.

Sign up to request clarification or add additional context in comments.

1 Comment

start /d "auth-service" %command% should do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.