set port nextjs
To set the port for a Next.js application, you can follow these steps:
Open the Next.js project folder in your preferred code editor.
Locate the
next.config.js
file in the root directory of your project. If the file doesn't exist, you can create one.Inside the
next.config.js
file, define theserver
object with aport
property. This property will specify the port number you want to use for your Next.js application.
javascript
// next.config.js
module.exports = {
server: {
port: 3000, // Replace with the desired port number
},
};
In the above example, the port
property is set to 3000
. You can change it to any available port number of your choice.
Save the
next.config.js
file.If your Next.js application is running, stop the server (if applicable).
Start your Next.js application again. It will now use the port number you specified in the
next.config.js
file.
By setting the port
property in the next.config.js
file, you can specify the port number for your Next.js application. This allows you to run the application on a specific port when starting the development server.