Node.js 12.22.0
or laterNext.js
app using create-next-app
, which sets up everything automatically for you. To create a project, run:npx create-next-app@latest
# or
yarn create next-app
# or
pnpm create next-app
--typescript
flag :npx create-next-app@latest --typescript
# or
yarn create next-app --typescript
# or
pnpm create next-app --typescript
npm run dev
or yarn dev
or pnpm dev
to start the development server on http://localhost:3000
http://localhost:3000
to view your applicationpages/index.js
and see the updated result in your browsernext
, react
and react-dom
in your project:npm install next react react-dom
# or
yarn add next react react-dom
# or
pnpm add next react react-dom
package.json
and add the following scripts :"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
dev
- Runs next dev
to start Next.js in development modebuild
- Runs next build
to build the application for production usagestart
- Runs next start
to start a Next.js production serverlint
- Runs next lint
to set up Next.js' built-in ESLint configurationpages
and public
at the root of your application:pages
- Associated with a route based on their file name. For example pages/about.js
is mapped to /about
public
- Stores static assets such as images, fonts, etc. Files inside public directory can then be referenced by your code starting from the base URL (/).Next.js
is built around the concept of pages. A page is a React Component exported from a .js
, .jsx
, .ts
, or .tsx
file in the pages directory. You can even add dynamic route parameters with the filename.index.js
file to get started. This is the page that is rendered when the user visits the root of your applicationpages/index.js
with the following contents :function HomePage() {
return <div>Welcome to Next.js!</div>
}
export default HomePage
npm run dev
or yarn dev
or pnpm dev
to start the development server on http://localhost:3000
http://localhost:3000
to view your applicationpages/index.js
and see the updated result in your browser