1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 23:58:01 +00:00

Add Run Multiple Node Scripts Concurrently as a JavaScript TIL

This commit is contained in:
jbranchaud
2023-12-22 10:20:03 -06:00
parent 678f327cb9
commit 5f20cd569e
2 changed files with 40 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1359 TILs and counting..._
_1360 TILs and counting..._
---
@@ -467,6 +467,7 @@ _1359 TILs and counting..._
- [Reach Into An Object For Nested Data With Get](javascript/reach-into-an-object-for-nested-data-with-get.md)
- [Render An Array Of Elements With React 16](javascript/render-an-array-of-elements-with-react-16.md)
- [Resolve And Pass Multiple Values From A Then](javascript/resolve-and-pass-multiple-values-from-a-then.md)
- [Run Multiple Node Scripts Concurrently](javascript/run-multiple-node-scripts-concurrently.md)
- [Running ES6 Specs With Mocha](javascript/running-es6-specs-with-mocha.md)
- [Scoping Variables With A Block Statement](javascript/scoping-variables-with-a-block-statement.md)
- [Sleep For A Bit In Async Code](javascript/sleep-for-a-bit-in-async-code.md)

View File

@@ -0,0 +1,38 @@
# Run Multiple Node Scripts Concurrently
The [`concurrently` npm
package](https://github.com/open-cli-tools/concurrently) is a CLI for
concurrently running multiple commands or scripts. This is great for working in
the context of a web server development where you often need several pieces of
infrastructure running locally at once.
Assuming you have the `concurrently` package installed and there are several
dev scripts in your `package.json`, here is one way this could look:
```json
{
"scripts": {
"dev": "concurrently \"npm run dev:next\" \"npm run dev:inngest\" \"npm run dev:mailhog\"",
"dev:next": "next dev",
"dev:inngest": "pnpx inngest-cli@latest dev",
"dev:mailhog": "mailhog",
}
}
```
Running `npm run dev` would start a process that runs all three commands and
combines their output.
A shorthand way of writing this since these commands all have the same prefix
is:
```json
{
"scripts": {
"dev": "concurrently \"npm:dev:*\"",
"dev:next": "next dev",
"dev:inngest": "pnpx inngest-cli@latest dev",
"dev:mailhog": "mailhog",
}
}
```