Jay Modi
Jay Modi

Reputation: 639

Changing localhost port in VS Code

My 2 main folders are CMS and nextjs as shown below:

enter image description here

But when I go to run 1 folder it uses my localhost:3000 then the other also wants to use the same port but this is not possible as I get an error saying port 3000 already in use. Basically I want to run my CMS folder and nextjs folder in 2 different ports.

I have attached my launch.json code just incase:

{
"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "skipFiles": [
            "<node_internals>/**"
        ],
        "program": "${workspaceFolder}\\nextjs\\.next\\server\\pages\\index.js"
    }
]
} 

Upvotes: 0

Views: 5788

Answers (1)

Thibault Walterspieler
Thibault Walterspieler

Reputation: 2402

Next.js

You have to edit the package.json. In the script object you'll find a property named dev. You can edit it like this (ex: port 3005) :

"dev": "next dev -p 3005"

When you will launch npm run dev, you app will turn on port 3005

Strapi

Add a .env file at the root of your project and add a variable with the port you want:

PORT=3627

Read more in the Strapi documentation here

Upvotes: 4

Related Questions