nextjs docs

Installing Next.js

To create a new Next.js app, you can use create-next-app by running the following command in your terminal:

npx create-next-app@latest

Running Your Next.js App

Once the installation is complete, you can navigate to the newly created app directory and start the development server by running:

npm run dev
# or
yarn dev

Pages in Next.js

Next.js automatically handles routing based on the files you create in the pages directory. For example, a file named pages/about.js will be accessible at /about.

API Routes

You can create API routes in Next.js by adding files to the pages/api directory. These files should export a default function which handles the request and response.

Static File Serving

The public directory in Next.js is used to serve static files. Any file placed in the public directory can be accessed at the root of the application.

Customizing Next.js Configuration

You can customize the Next.js configuration by creating a next.config.js file in the root of your project. This file can be used to modify various aspects of the Next.js build process.

Pre-rendering and Data Fetching

Next.js supports both server-side rendering (SSR) and static site generation (SSG), providing flexibility for fetching and pre-rendering data. This can be achieved using the getServerSideProps and getStaticProps functions within a page component.