Next.js - Configurazione dell'ambiente
Poiché Next.js è un framework basato su React, stiamo usando l'ambiente Node. Ora assicurati di averlo fattoNode.js e npminstallato sul tuo sistema. È possibile utilizzare il seguente comando per installare Next.js:
npm install next react react-dom 
    È possibile osservare il seguente output una volta installato con successo Next.js:
+ [email protected]
+ [email protected]
+ [email protected]
added 831 packages from 323 contributors and audited 834 packages in 172.989s 
    Ora creiamo un nodo package.json -
npm init 
    Seleziona i valori predefiniti durante la creazione di un package.json -
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (nextjs)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to \Node\nextjs\package.json:
{
   "name": "nextjs",
   "version": "1.0.0",
   "description": "",
   "main": "index.js",
   "dependencies": {
      "next": "^9.4.4",
      "react": "^16.13.1",
      "react-dom": "^16.13.1"
   },
   "devDependencies": {},
   "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
   },
   "author": "",
   "license": "ISC"
}
Is this OK? (yes) 
    Ora aggiorna la sezione degli script di package.json per includere i comandi Next.js.
{
   "name": "nextjs",
   "version": "1.0.0",
   "description": "",
   "main": "index.js",
   "dependencies": {
      "next": "^9.4.4",
      "react": "^16.13.1",
      "react-dom": "^16.13.1"
   },
   "devDependencies": {},
   "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "dev": "next",
      "build": "next build",
      "start": "next start"
   },
   "author": "",
   "license": "ISC"
} 
    Crea directory di pagine.
Crea una cartella di pagine all'interno della cartella nextjs e crea un file index.js con i seguenti contenuti.
function HomePage() {
   return <div>Welcome to Next.js!</div>
}
export default HomePage 
    Avvia Next.js Server
Eseguire il comando seguente per avviare il server -.
npm run dev
> [email protected] dev \Node\nextjs
> next
ready - started server on http://localhost:3000
event - compiled successfully
event - build page: /
wait  - compiling...
event - compiled successfully
event - build page: /next/dist/pages/_error
wait  - compiling...
event - compiled successfully 
    Verifica output
Apri localhost: 3000 in un browser e vedrai il seguente output.