Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set port in next.js

one application is running on port 3000 and I want to run another application on a different port of the default port. How I change this in React Next.js. My package.js script is

"scripts": {     "test": "echo \"Error: no test specified\" && exit 1",     "dev": "next",     "build": "next build",     "start": "next start"   }, 

and start script command is npm run dev

like image 707
Sohail Ahmad Avatar asked Feb 10 '20 09:02

Sohail Ahmad


People also ask

What port does NextJS run on?

Run npm run dev and the NextJS application will start on port 3002.

How do I change the port in react?

To change the default port for a create-react-app project, update the start command in your package. json file to specify the port, e.g. "PORT=3456 react-scripts start" on macOS and Linux and "set PORT=3456 && react-scripts start" on Windows.


2 Answers

This work for me

 "scripts": {         "dev": "next -p 8080"  }, 
like image 178
Sohail Ahmad Avatar answered Oct 18 '22 19:10

Sohail Ahmad


"scripts": {     "dev": "next dev -p 8080", // for dev      "start": "next start -p 8080" // for prod }, 
like image 28
Alongkorn Avatar answered Oct 18 '22 19:10

Alongkorn