7

I have been working on Vue.js and Node.js to build my app. When I have started with Vue it is by default running on 8080 and Node I am running on 3008.

What I am trying to do is due to some circumstances I want to change the port for Vue from 8080 to any other like 8086 or 3005. How can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
manish thakur
  • 760
  • 9
  • 35
  • 76

7 Answers7

15

Simply you can run the following command to run vue app as per your required port :

npm run serve --port 8086

Another way is to update the serve script command in your package.json file. Just append --port 8086 like so:

"scripts": {
  "serve": "vue-cli-service serve --port 8086",
  "build": "vue-cli-service build",
  "inspect": "vue-cli-service inspect",
  "lint": "vue-cli-service lint"
}
Rahul Gupta
  • 991
  • 4
  • 12
6

This is the way! ...that worked for me!

npm run serve -- --port 8086
virtuvious
  • 2,362
  • 2
  • 21
  • 22
  • 1
    Thanks. I have used run `npm run serve --port 8081`, but it ends up with error message `TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (8081)`. – ibnɘꟻ Sep 02 '21 at 03:13
5

If you don't have one create vue.config.js in the root dir of your project and there add this option:

module.exports = {
   devServer: {
      port: 8086
   }
}

In webpack docs you can see all the available options for configuring the dev server.

Check also vue-cli docs.

Slim
  • 1,924
  • 1
  • 11
  • 20
1

With npm:

npm run serve --port 8086

With yarn:

yarn serve --port 8086
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

If you are using vite as your build tool, you can override the default port with the one you want by providing a server.port entry in the vite configuration file - vite.config.js

In the example below, I set the default port to 8086

export default defineConfig({
  ...

  server: {
    port: 8086,
  },
});
Francis Kisiara
  • 125
  • 2
  • 14
0

in vue.config.js

module.exports = defineConfig({
  ...
  devServer: {
    port: 8086,
  },
user7331530
  • 815
  • 1
  • 12
  • 21
-4

DIR: node_modules@vue\cli-service\lib\commands CHANGE FILE: serve.js

const defaults = { host: '0.0.0.0', port: 8086, https: false }

Utkir
  • 1