AI Hints
Home›CI/CD with GitHub Actions Tutorial›Fast Feedback and Node.js
CI/CD with GitHub Actions · Lesson 65 of 138

A Node.js Pipeline

JavaScript projects.

⏱ 2 min read▶ Video at 1:14:15🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

CI isn't just for Python. Let's set up a pipeline for a small JavaScript project, a cart library with Node's built in test runner. The ideas are exactly the same. Only the tools change.

A Node.js Pipeline
From the video: A Node.js Pipeline
  • Not just Python
  • A JavaScript cart
  • Same ideas, new tools

The project

Cat shows the package dot JSON. Its scripts section defines test, which runs node dash dash test, and lint, which checks the syntax. NPM test runs the two tests, and both pass. These scripts are exactly what CI will call.

Terminal
cat package.json
{
  "name": "cart",
  "version": "1.0.0",
  "scripts": {
    "test": "node --test",
    "lint": "node --check cart.js"
  }
}
npm test 2>&1 | grep -E "^# (tests|pass|fail)"
# tests 2
# pass 2
# fail 0

node.yml

Setup node installs the Node version from the matrix, eighteen, twenty, and twenty two, and caches the NPM downloads. NPMCI installs the exact dependencies from the lock file. Then we run the lint script and the tests.

.github/workflows/node.ymlyaml
name: Node CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [18, 20, 22]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test

Running it

Our helper runs each matrix job. Locally, the sandbox has one Node version, so all three use it, but on GitHub, setup node would install each version. NPMCI, lint, and the tests pass in every job.

Terminal
run-steps .github/workflows/node.yml | grep -E "^Job|npm test|Job succ"
Job: test (18)
  ✓ Run npm test
  Job succeeded
Job: test (20)
  ✓ Run npm test
  Job succeeded
Job: test (22)
  ✓ Run npm test
  Job succeeded

Summary

A Node pipeline uses setup node, NPMCI, and the project's own scripts. Next, why NPMCI matters.

Key takeaways
  • actions/setup-node
  • npm ci
  • npm test
Next up: npm ci and Lockfiles — the same versions everywhere