Home / Configs / Developer tools / GitHub Actions workflow for Node.js

GitHub Actions workflow for Node.js: run tests on every push

A ci.yml file that installs, lints, builds and tests your Node.js project on GitHub.

For a Node.js project in a GitHub repository that has a package-lock.json.

A GitHub Actions workflow runs your checks on GitHub's servers each time you push code. This one installs your packages and runs the steps you choose. Fill in the options, save the file in your repository, and push.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Usually main or master

.github/workflows/ci.yml
name: CI

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 24
          cache: npm
      - run: npm ci
      - run: npm run lint --if-present
      - run: npm run build --if-present
      - run: npm test

How this setup works

Diagram: git push, then GitHub Actions, then Pass or fail
git push (to GitHub) → GitHub Actions (starts the workflow) → Pass or fail (shown on the commit)

Step-by-step setup

  1. In your repository create the folder .github/workflows.
  2. Save the file above there as ci.yml.
  3. Commit and push to the main branch.
  4. Open the Actions tab on GitHub to watch the run.
  5. A green tick on your commit means every step passed.

What the important lines mean

Common errors and how to fix them

npm error The npm ci command can only install with an existing package-lock.json
The lock file is not committed. Run npm install locally and commit package-lock.json.
npm error Missing script: "test"
package.json has no test script. Add one under "scripts", or untick the test step.
The workflow does not start
The file must be in .github/workflows and end in .yml or .yaml. The push must be to the branch named in the file.
Error: Unexpected value or a YAML error
Indentation is wrong. YAML uses spaces, never tabs. Paste the file into a YAML checker to find the line.

Frequently asked questions

Where do I put a GitHub Actions workflow file?
In the .github/workflows folder at the top of your repository. Each .yml file there is a separate workflow.
How do I run a workflow only on one branch?
List the branch under on: push: branches:, as this file does for your chosen branch.
Do the action versions need updating?
From time to time. The @v4 parts are version tags. GitHub shows newer versions in the action's own page, and Dependabot can update them for you.

Written for: GitHub Actions on ubuntu-latest · Updated 2026-10-11

More developer configs

See all 41 config generators