To change the port of a Next.js app, there are two ways:
Way One: package.json
In package.json add "-p 3001" to "dev" or "start", whether you want to change the port for development or production. your package.json may look like this now:
"scripts": { "dev": "next dev -p 3001", "build": "next build", "start": "next start", "lint": "next lint", "export": "next build && next export" },
When you run $ npm run dev, the URL will be http://localhost:3001
Way Two: Command line
When starting the development or production server, add "-- -p 3001" to the command, so it may be:
$ npm run start -- -p 3001
Same as before, the url will be http://localhost:3001