Next.js is a wonderful production framework for React. This framework has two ways to create a Next Js App. The first way is using a boilerplate from Next Js APP, to use this tool, perform the following steps.
Before, you should have installed, one tool for package management such as npm or yarn.
Create next-app Tool.
1.Yarn
yarn create next-app
OR
1.Npm
npm create next-app
NPM OR YARN.
The assistant should ask your app name, in this case, write a name for your app and press the KEY ENTER.Now your app structure was created, enter to App directory.
cd my-app
- Enjoy! Now you can run the application, create a build, and finally run the application in production mode.
// Run Dev Server
yarn dev
yarn build // Create a build
yarn start // run server in production mode after a build
You can use the same commands with npm, only replace the word "yarn" for "npm"
Manually.
To create the structure app manually perform the next steps:
- Make a directory with the name of your application. In the console write:
mkdir next-js-app
Enter to Directory. In the console write: cd next-js-app
NPM: npm install next react react-dom OR Yarn write:
yarn add next react react-dom
npm install next react react-dom
OR
yarn add next react react-dom
- Edit the file Package.Json, and add in the scripts section, the next lines.
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
- Now, you need a page directory: In the root directory, create a directory named pages. Example: mkdir pages
mkdir pages
Enjoy, now you can run the app. for example in dev mode.
npm run dev.
Top comments (1)
Why don't you also explain npx?