# npm Scripts — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-npm-scripts

> Wrap common commands behind short names.

## The scripts field

Define named commands in `package.json`, then run them with `npm run`.

```json
{
  "scripts": {
    "start": "node index.js",
    "dev": "node --watch index.js",
    "test": "node --test"
  }
}
```

## Running scripts

`start` and `test` are special — run them without `run`.

```bash
npm start        # runs "node index.js"
npm test         # runs "node --test"
npm run dev       # custom scripts need "run"
```

**Quiz:** Which two script names can you run without typing `run`?

- [x] start and test
- [ ] dev and build
- [ ] install and stop

*Answer:* start and test. `npm start` and `npm test` are shortcuts baked into npm; every other script name needs `npm run <name>`.
