6.1.0 • Published 6 months ago

@rowanmanning/not-found v6.1.0

Weekly downloads
21
License
MIT
Repository
github
Last release
6 months ago

@rowanmanning/not-found

Create Express middleware which results in an HTTP 404 Not Found error.

Requirements

This library requires the following to run:

Usage

Install with npm:

npm install @rowanmanning/not-found

Load the library into your code with a require call:

const { notFound } = require('@rowanmanning/not-found');

Create middleware which results in an HTTP 404 error in Express:

const express = require('express');
const { notFound } = require('@rowanmanning/not-found');

const app = express();

app.use(notFound());

Handle the 404 error like you would any other error in Express:

app.use((error, request, response, next) => {
    response.status(error.status); // 404
    response.send(error.message); // Not Found
});

Customise the error message with an option:

app.use(notFound({
    message: 'This page does not exist'
}));

app.use((error, request, response, next) => {
    response.status(error.status); // 404
    response.send(error.message); // This page does not exist
});

Migration

A new major version of this project is released if breaking changes are introduced. We maintain a migration guide to help users migrate between these versions.

Contributing

The contributing guide is available here. All contributors must follow this library's code of conduct.

License

Licensed under the MIT license. Copyright © 2019, Rowan Manning

6.1.0

6 months ago

6.0.0

8 months ago

5.2.1

1 year ago

5.2.0

1 year ago

5.1.0

2 years ago

5.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.0.3

3 years ago

3.1.0

3 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.5

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago