# Node.js CI workflow

> GitHub's official Node.js CI starter workflow, explained and hardened by Latchkey.

Source: https://latchkey.dev/workflows/nodejs-ci  
Upstream: [GitHub official starter workflow](https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml) (ci/node.js.yml), licence CC0-1.0

## What it does

This is the Node.js continuous integration workflow GitHub offers by default. It checks out the repo, installs a matrix of Node versions, installs dependencies with `npm ci`, and runs the build and tests.

It is a solid starting point. Below, Latchkey adds the guardrails the starter leaves out.

## The workflow

```yaml
name: Node.js CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x, 22.x]
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test
```

## FAQ

### What does the Node.js CI workflow workflow do?

This is the Node.js continuous integration workflow GitHub offers by default. It checks out the repo, installs a matrix of Node versions, installs dependencies with npm ci, and runs the build and tests.

### What CI health grade does this workflow get?

This Node.js workflow grades C. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.

### How can I improve this Node.js workflow?

Add run de-duplication and job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
