Step-by-step instructions to start using Next.js
To install Next.js, you needNode.jsIt has been installed.
Make sure you have the latest version of Node. Running checknode -v
In your terminal and compare it with the latest LTS version listedhttps://nodejs.org/.
After installing Node.js, you will havenpm
Commands can be used on your command line.
If you encounter any trouble at this stage, I suggest you write the following tutorial for me:
- How to install Node.js
- How to update Node.js
- Introduction to npm package manager
- Unix Shell Tutorial
- How to use macOS terminal
- Whack the shell
Now you have updated Node to the latest version, andnpm
, Create an empty folder in any location you like (for example, in the main folder), and then enter that folder:
mkdir nextjs
cd nextjs
And create your first Next project
mkdir firstproject
cd firstproject
Use nownpm
Initialize it as a command for the Node project:
npm init -y
This-y
Option tellnpm
Use the project’s default settings to fill in the examplepackage.json
file.
Now install Next and React:
npm install next react react-dom
Your project folder should now have 2 files:
package.json
(Just see my tutorial)package-lock.json
(See my package lock tutorial)
withnode_modules
folder.
Use your favorite editor to open the project folder. My favorite editor isVS code. If it is installed, you can runcode .
Open the current folder in the editor in the terminal (if this command does not work for you, please refer toThis)
turn onpackage.json
, Now has the following content:
{
"name": "airbnbclone",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"next": "^9.1.2",
"react": "^16.11.0",
"react-dom": "^16.11.0"
}
}
And replacescripts
The section with the following content:
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
Add Next.js build command, we will use it soon.
Create one nowpages
Folder and add aindex.js
file.
In this file, let's create the first React component.
We will use it as the default export:
const Index = () => (
<div>
<h1>Home page</h1>
</div>
)
export default Index
Now use the terminal and runnpm run dev
Start the Next development server.
This will make the application available on port 3000 on the local host.
turn onhttp://localhost:3000View it in the browser.
Download mine for freeNext.js manual
More tutorials next:
- Getting started with Next.js
- Next.js vs Gatsby vs create-react-app
- How to install Next.js
- Use links to link two pages in Next.js
- Dynamic content in Next.js in the router
- Use getInitialProps to feed data to Next.js components
- Use CSS to style Next.js components
- Prefetch content in Next.js
- Use a router to detect active links in Next.js
- Check the source code to confirm that SSR is working properly in Next.js
- Next.js: Fill the head tag with a custom tag
- Deploy the Next.js application now
- Next.js: Only run code on the server or client side of Next.js
- Deploy Next.js application in production
- How to analyze Next.js application bundles
- Lazy loading module in Next.js
- Add a wrapper component to your Next.js application
- Add Next.js to the icon in your application
- Next.js application bundle
- How to use Next.js router
- How to use Next.js API routing
- How to get cookies on the server side in Next.js application
- How to change the Next.js application port