You need to follow below mentioned steps
Pre-Requisites
Node JS – The latest version of Node JS installed, if it is not then please installed from Download Node JS.
Sitecore - Running instance of latest Sitecore XP/XM with Sitecore Headless packages installed in it. If it is not then please install
Download and install Sitecore Experience Platform from https://developers.sitecore.com/downloads/Sitecore_Experience_Platform
Download Sitecore Headless Rendering package and install it in Sitecore instance from
https://developers.sitecore.com/downloads/Sitecore_Headless_Rendering
PowerShell – To execute commands
Steps to setup the application
- Install Sitecore JSS CLI
Open the Windows PowerShell in Admin mode
Run the following Command
npm install -g @sitecore-jss/sitecore-jss-cli
2.Create next js application
Move to the directory when the project to be created, for my case it is
C://Learning/NextJS
Execute below command, it will create new application under the mentioned location
npm init sitecore-jss nextjs
Here I'm adding links of blogs where you can find more details.
Setting Up Sitecore Headless with Next.js in Disconnected Mode
Setting Up Sitecore Headless with Next.js in connected Mode
Hope this help!! Let me know If you need further help...