### Manual Next.js Installation using npm Source: https://nextjs.org/docs/13/getting-started/installation Manually installs Next.js, React, and ReactDOM using npm. This method requires manually adding scripts to the `package.json` file for development, building, starting, and linting. ```bash npm install next@latest react@latest react-dom@latest ``` -------------------------------- ### Create Next.js App with Playwright Example Source: https://nextjs.org/docs/13/pages/building-your-application/optimizing/testing Initializes a new Next.js project with Playwright pre-configured. This command uses `create-next-app` with a specific example to streamline the setup process for end-to-end testing. ```bash npx create-next-app@latest --example with-playwright with-playwright-app ``` -------------------------------- ### Automatic Next.js Installation with create-next-app Source: https://nextjs.org/docs/13/getting-started/installation Installs a new Next.js project using the `create-next-app` command-line tool. This method automatically configures TypeScript, ESLint, Tailwind CSS, and the App Router based on user prompts. It requires Node.js 16.14 or later. ```bash npx create-next-app@latest ``` -------------------------------- ### Create Next.js App with Cypress Example Source: https://nextjs.org/docs/13/pages/building-your-application/optimizing/testing Command to create a new Next.js application pre-configured with Cypress using the official `create-next-app` tool. This provides a quick starting point for E2E testing. ```bash npx create-next-app@latest --example with-cypress with-cypress-app ``` -------------------------------- ### Install OpenTelemetry Packages for Manual Setup Source: https://nextjs.org/docs/13/app/building-your-application/optimizing/open-telemetry Installs the necessary OpenTelemetry packages for manual configuration in a Node.js environment. These packages provide the core SDK and exporters for tracing. ```bash npm install @opentelemetry/sdk-node @opentelemetry/resources @opentelemetry/semantic-conventions @opentelemetry/sdk-trace-node @opentelemetry/exporter-trace-otlp-http ``` -------------------------------- ### Start Production Server Source: https://nextjs.org/docs/13/app/api-reference/next-cli Starts the application in production mode. Includes configuration for custom ports and keep-alive timeouts for proxy compatibility. ```bash npx next start -p 4000 PORT=4000 npx next start npx next start --keepAliveTimeout 70000 ``` -------------------------------- ### GET /api/post/[pid] Source: https://nextjs.org/docs/13/pages/building-your-application/routing/api-routes Example of handling dynamic API routes using path parameters. ```APIDOC ## GET /api/post/[pid] ### Description Retrieves data based on a dynamic path parameter `pid`. ### Method GET ### Endpoint /api/post/:pid ### Parameters #### Path Parameters - **pid** (string) - Required - The dynamic identifier for the post. ### Response #### Success Response (200) - **body** (string) - Returns the post ID string. ### Response Example "Post: abc" ``` -------------------------------- ### Start Development Server Source: https://nextjs.org/docs/13/app/api-reference/next-cli Starts the application in development mode with hot-reloading. Supports custom port and hostname configuration via CLI flags or environment variables. ```bash npx next dev -p 4000 PORT=4000 npx next dev npx next dev -H 192.168.1.2 ``` -------------------------------- ### Create Functional Code Examples Source: https://nextjs.org/docs/13/community/contribution-guide Examples of standard code blocks in Next.js documentation, including TypeScript components and terminal commands with filenames. ```tsx import Link from 'next/link' export default function Page() { return About } ``` ```bash npx create-next-app ``` -------------------------------- ### Create Next.js App with Jest Example Source: https://nextjs.org/docs/13/pages/building-your-application/optimizing/testing Initializes a new Next.js project with Jest and React Testing Library pre-configured. This command uses `create-next-app` with a specific example to quickly set up a project for unit testing. ```bash npx create-next-app@latest --example with-jest with-jest-app ``` -------------------------------- ### Configure Next.js build and start scripts Source: https://nextjs.org/docs/13/app/building-your-application/deploying Defines the necessary scripts in package.json to enable building and starting a Next.js production server. ```json { "scripts": { "dev": "next dev", "build": "next build", "start": "next start" } } ``` -------------------------------- ### Define Documentation File Structure Source: https://nextjs.org/docs/13/community/contribution-guide Examples of file-system routing used in the documentation. It demonstrates how to use numeric prefixes to control the sorting order of navigation items. ```text 03-functions ├── cookies.mdx ├── draft-mode.mdx ├── fetch.mdx └── ... 02-routing ├── 01-defining-routes.mdx ├── 02-pages-and-layouts.mdx ├── 03-linking-and-navigating.mdx └── ... ``` -------------------------------- ### Install Sharp for Image Optimization Source: https://nextjs.org/docs/13/app/api-reference/next-config-js/output Installs the sharp library, which is a required dependency for Next.js Image Optimization when using the default loader. ```bash npm i sharp ``` ```bash yarn add sharp ``` ```bash pnpm add sharp ``` ```bash bun add sharp ``` -------------------------------- ### Install Cypress for Next.js Source: https://nextjs.org/docs/13/pages/building-your-application/optimizing/testing Installs the Cypress testing framework as a development dependency for a Next.js project. This is the first step for setting up E2E or Component Testing with Cypress. ```bash npm install --save-dev cypress ``` -------------------------------- ### Create Documentation Notes Source: https://nextjs.org/docs/13/community/contribution-guide Formats important information using blockquotes to create distinct note sections for users. ```mdx > **Good to know**: This is a single line note. > **Good to know**: > > - We also use this format for multi-line notes. > - There are sometimes multiple items worth knowing or keeping in mind. ``` -------------------------------- ### Install server-only package Source: https://nextjs.org/docs/13/app/building-your-application/rendering/composition-patterns Command to install the 'server-only' package, which is used to prevent accidental usage of server-side modules in client-side code. ```bash npm install server-only ``` -------------------------------- ### Root Layout Example Source: https://nextjs.org/docs/13/app/api-reference/file-conventions/layout Example of the root layout component, defining the base HTML structure. ```APIDOC ## Root Layout ### Description The top-most layout in the `app` directory, responsible for defining the `` and `` tags and other global UI. ### Method N/A (Component Definition) ### Endpoint N/A (Component Definition) ### Parameters #### Props - **children** (React.ReactNode) - Required - The content to be rendered within the layout, typically including the rest of the application. ### Request Example ```typescript export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( {children} ) } ``` ### Response #### Success Response (Rendered HTML Structure) - **children** (React.ReactNode) - The rendered content of the entire application. #### Response Example ```html ``` ``` -------------------------------- ### Install Jest dependencies Source: https://nextjs.org/docs/13/pages/building-your-application/optimizing/testing Installs the necessary packages for Jest testing, including the JSDOM environment and React testing library utilities. ```bash npm install --save-dev jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom ``` -------------------------------- ### Set Application Port with `PORT` Environment Variable Source: https://nextjs.org/docs/13/pages/building-your-application/upgrading/version-11 Example of how to set the application port for `next dev` or `next start` using the `PORT` environment variable. This is an alternative to the `-p` or `--port` flags. ```bash PORT=4000 next start ``` -------------------------------- ### Example: Advanced Module Aliases with baseUrl and paths Source: https://nextjs.org/docs/13/pages/building-your-application/configuring/absolute-imports-and-module-aliases This example showcases advanced configuration using both `baseUrl` and `paths` to alias multiple directories, such as `@/styles/*` and `@/components/*`. It also shows importing a helper utility from a non-aliased path (`utils/helper`). ```javascript import Button from '@/components/button' import '@/styles/styles.css' import Helper from 'utils/helper' export default function HomePage() { return (

Hello World