npm start service --- modify service port number

Table of contents

foreword

positive

expand


foreword

Because it is the main back end, the front end has only learned a little bit. During the development process, I wanted to start the react project service on a different port, so I studied it online and recorded it.

positive

When we start the vue or react project, if we use npm, the startup command is nothing more than

npm install

npm start

If it is not configured after normal startup, the default port number of vue is 8080, and the default port number of create-react-app is 3000

So how to modify it? 

There are many ways to modify the port number to start the service. The following list them one by one. If there are any deficiencies, please advise:

1. Directly specify in the startup command   ( self-test is useless, self-defense haha )

npm start -- -p xxxx //Pay attention to the -- between start and -p here! !

2. Configure in the package.json file ( self-test is valid, so recommended! )

  "scripts": {
    "start": "set port=50000 && craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },

 By the way, because I used the craco configuration tool, it should actually be the same, so let's try it out.

3. The vue project can be configured in vue.config.js

Extracted from the blogger , because I am the main react, this method has not been tried, you can try it yourself to see if it works.

const {defineConfig} = require('@vue/cli-service')
module.exports = defineConfig({
    transpileDependencies: true,
    //更改默认端口
    devServer: {
        open: false, // 自动打开浏览器
        port: 8081,
    },
    //设置是否在开发环境下每次保存代码时都启用 eslint验证
    lintOnSave: false
})

 

expand

Just started to play custom configuration port number, set a 90000 at once . Report a mistake to myself and laugh

Could not find an open port at 0.0.0.0.
Network error message: options.port should be >= 0 and < 65536. Received 90000.

 

The maximum service port number of a single ip is 65535 , which is the foundation of the foundation, and I forgot to play with it. .

The following reference comes from the experience of the predecessors , the students learned and extracted the necessary parts, thank you!

This also reviews ip and port by the way. In the operating system, the range of port numbers is 0-65535, among which 0-1024 are reserved port numbers, which cannot be used , and other ports can be used. That is to say, at the link initiator, limited by the port number, theoretically a maximum of 64,000 links can be created.

For the link initiator, the local ip and port affect the number of links. The port number is limited to 65535, and there is no way to increase it. Then we can increase the local ip to achieve this goal. Under normal circumstances, only one ip is bound to one network card of the server, and this ip is used for external communication. In fact, the network card supports one binding to multiple IPs (you must ensure that the ip is valid and unused)

Every time the server network card adds an ip, it can allow about 65535 more connections to be created on this ip.

The above is the whole of this article, I hope to keep a humble heart at all times, and I also hope to be excellent and better, and I am always on the road!

Guess you like

Origin blog.csdn.net/Ccc67ol/article/details/130240490