4xx Client ErrorCommonly usedRFC 9110

404Not Found

The requested resource does not exist.

What it means

The server cannot find the requested resource. The URL may be wrong, the resource may have been deleted, or it may never have existed. 404 does not indicate whether the absence is temporary or permanent.

When to use it

  • Resource with the given ID does not exist
  • URL path does not match any route
  • File has been deleted
  • User is trying to access a non-existent page

Common causes

  • Typo in the URL
  • Resource was deleted
  • ID does not exist in the database
  • Route not defined on the server

Code Examples

Express — 404 handler
javascript
app.get('/users/:id', async (req, res) => {
  const user = await db.users.findById(req.params.id);
  if (!user) {
    return res.status(404).json({
      error: 'Not Found',
      message: `User ${req.params.id} does not exist`,
    });
  }
  res.json(user);
});

// Catch-all 404
app.use((req, res) => {
  res.status(404).json({ error: 'Route not found' });
});
Next.js — not-found.tsx
typescript
// app/not-found.tsx
export default function NotFound() {
  return (
    <div>
      <h2>404 — Page Not Found</h2>
      <p>Could not find the requested resource.</p>
    </div>
  );
}

// In a server component:
import { notFound } from 'next/navigation';
const user = await getUser(id);
if (!user) notFound(); // renders not-found.tsx

Quick Facts

Code404
CategoryClient Error
SpecRFC 9110
CommonYes
← Back to all status codes