# grunt-link-checker

> Finds broken links and resources on websites

Latest version **0.2.0** (published 2016-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install grunt-link-checker
pnpm add grunt-link-checker
yarn add grunt-link-checker
bun add grunt-link-checker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2016-08-03 |
| First published | 2014-05-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Wren |
| Maintainers | chriswren |
| Keywords | grunt, plugin, gruntplugin, link-checker, broken, links, crawler |

## Links

- npm: https://www.npmjs.com/package/grunt-link-checker
- Repository: https://github.com/chriswren/grunt-link-checker
- Issues: https://github.com/chriswren/grunt-link-checker/issues
- npm.io page: https://npm.io/package/grunt-link-checker

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^1.0.0
- [cheerio](https://npm.io/package/cheerio.md) ^0.20.0
- [simplecrawler](https://npm.io/package/simplecrawler.md) ^0.7.0

## Recent versions

- 0.2.0 (latest) — 2016-08-03
- 0.1.0 — 2015-04-21
- 0.0.6 — 2014-07-20
- 0.0.5 — 2014-06-20
- 0.0.4 — 2014-06-19
- 0.0.3 — 2014-05-26
- 0.0.2 — 2014-05-19
- 0.0.1 — 2014-05-18
- 0.0.0 — 2014-05-18

## README

# grunt-link-checker

> Run [node-simple-crawler](https://github.com/cgiffard/node-simplecrawler) to discover broken links on your website.

[![NPM version](https://img.shields.io/npm/v/grunt-link-checker.svg)](https://www.npmjs.com/package/grunt-link-checker)
[![Build Status](https://img.shields.io/travis/ChrisWren/grunt-link-checker/master.svg)](https://travis-ci.org/ChrisWren/grunt-link-checker)
[![Dependency Status](https://img.shields.io/david/ChrisWren/grunt-link-checker.svg)](https://david-dm.org/ChrisWren/grunt-link-checker)
[![devDependency Status](https://img.shields.io/david/dev/ChrisWren/grunt-link-checker.svg)](https://david-dm.org/ChrisWren/grunt-link-checker#info=devDependencies)

## Getting Started

If you haven't used grunt before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:

```shell
npm install grunt-link-checker --save-dev
```

Then add this line to your project's `Gruntfile.js` gruntfile:

```js
grunt.loadNpmTasks('grunt-link-checker');
```

## Documentation

grunt-link-checker will by default find any broken internal links on the given `site` and will also find broken [fragment identifiers] by using [cheerio](https://github.com/cheeriojs/cheerio) to ensure that an element exists with the given identifier. You can figure more [options that are available via node-simplecrawler](https://github.com/cgiffard/node-simplecrawler#configuring-the-crawler).

### Minimal Usage

The minimal usage of grunt-link-checker runs with a `site` specified and an optional `options.initialPort`:

```js
linkChecker: {
  dev: {
    site: 'localhost',
    options: {
      initialPort: 9001
    }
  }
}
```

### Recommended Usage

In addition to the above config which tests a local version of your site before deployment, you can add an additional target to run post-deployment. This will verify that your assets were deployed correctly and are being resolved correctly after any revisioning or path modifications during deployment:

```js
linkChecker: {
  // Use a large amount of concurrency to speed up check
  options: {
    maxConcurrency: 20
  },
  dev: {
    site: 'localhost',
    options: {
      initialPort: 9001
    }
  },
  postDeploy: {
    site: 'mysite.com'
  }
}
```

### Custom options

#### checkRedirect

* Type: `Boolean`
* Default: `false`

Set this to `true` to check for redirects.

#### noFragment

* Type: `Boolean`
* Default: `false`

Set this to `true` to speed up your test by not verfiying [fragment identifiers].

#### callback

Type: `Function`

Function that receives the instantiated `crawler` object so that you can add [events](https://github.com/cgiffard/node-simplecrawler#events) or other listeners/config to the crawler.

Here is an example config using the `callback` option to ignore `localhost` links which have different ports:

```js
linkChecker: {
  dev: {
    site: 'localhost',
    options: {
      initialPort: 9001,
      callback: function (crawler) {
        crawler.addFetchCondition(function (url) {
          return url.port === '9001';
        });
      }
    }
  }
}
```

### simple-crawler options

Every option specified in the node-simplecrawler is available:

<https://github.com/cgiffard/node-simplecrawler#configuring-the-crawler>

## Changelog

* **0.2.0** - Updated dependencies.
* **0.1.0** - Updated dependencies, changed task name to `linkChecker`.
* **0.0.6** - Added logging for initially fetched URL and logged status codes for failed fetches.
* **0.0.5** - Added error reporting if initial `site` URL fails.
* **0.0.4** - Added `callback` option.
* **0.0.3** - Fixed repo link in package.json and fixed error reporting for a failed initial URL.
* **0.0.2** - Added `noFragment` flag.
* **0.0.1** - Check to make sure `#` URLs resolve to content with a corresponding ID.
* **0.0.0** - Initial release.

[fragment identifiers]: https://en.wikipedia.org/wiki/Fragment_identifier

---
_Source: https://npm.io/package/grunt-link-checker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
