Back to results for “Set”
Next.js › Next.js Project Setup & Configuration

What is the purpose of the next.config.js file in a Next.js project?

Beginner

Answer

The next.config.js file lets you customize how your Next.js application builds and runs, controlling things like allowed image domains, custom redirects, environment variable exposure, and various build optimizations, all in one central configuration file.
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  images: {
    remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }]
  }
};

module.exports = nextConfig;
Real-world example A team enables React strict mode and configures allowed image domains in their next.config.js file, centralizing important project wide settings in a single, easy to find location.

Common follow-ups: What common settings are typically found in next.config.js?;Do changes to next.config.js require restarting the development server?