CI/CD Pipelines: Reuse, Matrix, Cache, and Artifacts/Cache npm dependencies in GitHub Actions

Reuse package manager downloads between runs.

Section: Speed and portability

Cache npm dependencies in GitHub Actions

yaml
yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: npm
Explanation

Prefer built-in setup action caching when available because it is simpler and less error-prone.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Speed and portability
GitLab cache vs artifacts
Use cache for dependencies and artifacts for outputs.
OpenIn sheetyamlsame section
Upload build artifacts
Publish files from one job for later download or deploy.
OpenIn sheetyamlsame section
GitHub Actions test matrix
Run the same job across multiple Node versions.
GitLab matrix variables
Expand one logical job into multiple combinations.
GitHub reusable workflow
Call a shared workflow from another repository or workflow file.