# Exercise: Lost and Found CI

Add ESLint and Prettier to the Lost and Found Desk's API with npm scripts, fix every problem they report without changing what the API answers, and add a GitHub Actions workflow that lints, checks the format and runs the tests on every push.

Journeyman · Node.js · GitHub Actions · Software Development · Updated November 19, 2026

By Gregor Dzierzon

The Lost and Found Desk's API works, and its tests pass. But three students write it, each in their own style, a few likely mistakes have crept in, and nothing checks a push before it lands on GitHub. You'll give the project the same setup a team would: ESLint and Prettier with npm scripts, every problem they report fixed, and a GitHub Actions workflow that runs every check on every push. When you push, GitHub shows your first green run.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-node-lost-and-found-ci](https://github.com/ask-codey/exercise-node-lost-and-found-ci), also linked from the **Exercise** box beside the lesson. Clone it into your `nodejs-course` folder. In VS Code's terminal:

```bash
cd ~/nodejs-course
git clone https://github.com/ask-codey/exercise-node-lost-and-found-ci.git
```

Git makes a folder, `exercise-node-lost-and-found-ci`, with the exercise code inside. Open that folder in VS Code (**File > Open Folder**), open its terminal with **Terminal > New Terminal**, and install the packages:

```bash
npm install
```

ESLint, Prettier and the rest are already in `package.json` at exact versions, so `npm install` brings them all. *Get the Exercise Code with Git* walks through cloning step by step, if you'd like a reminder.

The folder holds:

- `app.js`: the API, for you to clean up. The comment at its top lists every request it answers.
- `items.js`: the found items and the claims, kept in memory, for you to clean up too.
- `server.js`: starts the API at `http://localhost:3100`.
- `lost-and-found.http`: the requests to try with REST Client.
- `app.test.js`: the API's own 9 tests, which pass already and must still pass at the end.
- `quality.test.js`: the exercise's 12 checks, on your scripts, your ESLint config, your files and your workflow. You don't need to change either test file.

## What to do

1. **Add three scripts** to `package.json`, beside `start`, `dev` and `test`: `"lint": "eslint ."`, `"format": "prettier --write ."` and `"format:check": "prettier --check ."`.
2. **Make `eslint.config.js`** at the top of the folder: a flat config with `js.configs.recommended`, `languageOptions: { globals: globals.node }`, and three rules: `eqeqeq: "error"`, `"prefer-const": "error"` and `"no-unused-vars": ["error", { argsIgnorePattern: "^_" }]`.
3. **Run `npm run lint` and fix all six problems** it reports in `app.js` and `items.js`. Change the code; never switch a rule off or add a disable comment. Run `npm test` after each fix: the API's tests must stay green.
4. **Run `npm run format`**, so Prettier lays out every file the same way.
5. **Make `.github/workflows/ci.yml`** (the folder `.github`, the folder `workflows` inside it, then the file): a workflow named `CI` that runs `on: [push, pull_request]`, with one job that `runs-on: ubuntu-latest`. Its steps, in this order: `uses: actions/checkout@v7`; `uses: actions/setup-node@v7` with `node-version: 26` and `cache: npm`; then `run: npm ci`, `run: npm run lint`, `run: npm run format:check` and `run: npm test`. Run `npm run format` again afterwards: Prettier formats YAML too.

## Check your work

```bash
npm test
```

It runs both test files, and no server needs to be running. At first the API's 9 tests (`API 1)` to `API 9)`) pass and the 12 checks (`1)` to `12)`) fail: that's expected, because nothing is set up yet. Each part you finish turns its checks green. A failing check says what's missing, for example *Add "lint": "eslint ." to the scripts in package.json.* Check 7 lists every problem ESLint still reports, with its file, line and column, and check 9 names the line of `ci.yml` that YAML couldn't read.

## Hints

- **A route parameter is text.** If `API 3)` turns red after you change a `==` to `===`, the id from the address is `"2"` and the item's id is `2`. *ESLint and Prettier for a Node Project* shows the fix: `Number(id)`.
- **The error handler needs all four parameters.** Express knows it by them, so `next` stays: rename it `_next`, which your `no-unused-vars` setting skips.
- **An import nothing uses can go,** line and all. A `let` that never gets a new value becomes `const`.
- **Copy the steps from the lesson.** *Tests on Every Push with GitHub Actions* has the whole workflow, line by line. Indent with two spaces, never tabs.
- **Run the steps yourself before you push:** `npm ci`, `npm run lint`, `npm run format:check`, `npm test`. If they pass on your computer, they pass on GitHub's.

## When you're done

Every test is green, and `npm run lint` and `npm run format:check` print no problems. The end of `npm test`:

```text
✔ 12) Then the steps run npm ci, npm run lint, npm run format:check and npm test, in that order (0.9482ms)
ℹ tests 21
ℹ suites 0
ℹ pass 21
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 615.4843
```

The last check happens on GitHub. When you push in *Submit your exercise* below, open your repository's **Actions** tab: a run of *CI* starts within seconds, and after a minute or so its job `lint-and-test` shows a green check beside every step, from checkout to `npm test`. If a step is red, open it and read its log; it's the same output you'd see on your computer.

Then add the status badge at the top of `README.md`, with your GitHub name and repository in the address, commit and push again:

```text
![CI](https://github.com/your-name/exercise-node-lost-and-found-ci/actions/workflows/ci.yml/badge.svg)
```

Look back at the six problems you fixed: which of them would have broken the API if someone had "fixed" it by deleting a line or switching a rule off, and which test would have told you?

## Submit your exercise

The exercise is how you finish this lesson. When your work is done, put it on GitHub in a repo of your own, then submit that repo's address here. *Hand In Your Work with Git* walks through each step.

1. On GitHub, click **+**, then **New repository**. Name it (for example `exercise-node-lost-and-found-ci`), choose **Public**, and click **Create repository**. Leave out the README: your folder already has one.
2. In VS Code's terminal, in your exercise folder, send your work to your new repo. Point your copy at your own repo, then commit and push:

   ```bash
   git remote set-url origin https://github.com/your-name/exercise-node-lost-and-found-ci.git
   git add .
   git commit -m "My solution"
   git push -u origin main
   ```

3. Paste your repo's address, such as `https://github.com/your-name/exercise-node-lost-and-found-ci`, into **Submit your exercise** on this page. The site checks that the repo is public and holds your commits, and then the lesson is complete.

Changed something after you submitted? Push it, and submit again: your latest submission is the one that counts.

## So what

This is how a team's repository looks from the first day of a job: a linter and a formatter that everyone runs the same way, and a pipeline that checks every push, so a mistake shows up as a red cross in minutes instead of a bug report days later.

## Key terms

- [ESLint](https://www.ask-codey.com/glossary/eslint)
- [Prettier](https://www.ask-codey.com/glossary/prettier)
- [Continuous Integration](https://www.ask-codey.com/glossary/continuous-integration)
- [Workflow](https://www.ask-codey.com/glossary/workflow)
- [Step](https://www.ask-codey.com/glossary/step-github-actions)

## Related

- [ESLint and Prettier for a Node Project](https://www.ask-codey.com/lessons/node-pro-eslint-and-prettier)
- [Tests on Every Push with GitHub Actions](https://www.ask-codey.com/lessons/node-pro-github-actions-ci)
- [Package Versions, npm ci and npm audit](https://www.ask-codey.com/lessons/node-npm-versions-and-lock-file)

Source: https://www.ask-codey.com/lessons/exercise-node-lost-and-found-ci
