Score:0

How can I find out where a port number for a React website is saved?

cn flag

I have a Debian machine, I can see that a React website is running on port 4173 but can't find out where it is so that I can change the port.

I assume it is in some config file somewhere.

  • it's not in package.json
{
  "name": "debiantest",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview --host"
  },
  "dependencies": {
    "react": "^18.0.0",
    "react-dom": "^18.0.0"
  },
  "devDependencies": {
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "@vitejs/plugin-react": "^1.3.0",
    "vite": "^2.9.5"
  }
}
  • I don't find this port or site listed in /etc/nginx/sites-enabled/default

  • with grep I found that the number is in node_modules/caniuse-lite/data/agents.js

"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","tC","","",""],E:"KaiOS Browser",F:{tC:1527811200}}}; node_modules/vite/dist/node/chunks/dep-3397b401.js: const port = (_b = options.port) !== null && _b !== void 0 ? _b : 4173;

but am not sure where I would change it.

Where else can I look for this port number?

djdomi avatar
za flag
your hunting maybe for an [x and y problem](https://faq-database.de/doku.php?id=en:x-and-y-problem). what is the business related question in here what do you really want to do?
cn flag
My business at the moment is improving my Linux administration skills, so I got a 5€/month Debian machine in the cloud at Hetzner and spend a little time a day learning how to administrate it, set up nginx, user accounts via SSH, set up a GraphQL server, etc. A few weeks ago I got a React site running at http://tanguay.eu:4173 but honestly don't know if I specified the port or if it was defined for me. I want to know how Linux experts would go about finding the port here, in order to understand this issue better.
Score:0
cn flag

Stop the react server process, and then restart it using strace. It will be a little noisy, but you would want to look for "open" calls. This will show you all of the files the react server is opening as it runs. One of those files should contain the configuration data.

Here's an example using a stock Apache HTTPD server:

strace -f httpd 2>&1 | grep open

Will show you that the httpd process opens lots of files, and looking at those, you can find valuable information in these:

open("/etc/httpd/conf/httpd.conf", O_RDONLY|O_CLOEXEC) = 3
open("/etc/httpd/conf.d/ssl.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/httpd/conf.d/perl.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/httpd/conf.d/php.conf", O_RDONLY|O_CLOEXEC) = 4

It's just an example, the React server will have different files, but you should be able to filter through them (ie. grep -v) until you find something useful.

mikem avatar
cn flag
PS Also keep in mind that some applications will use a default port that is hard-coded and only uses a value in a config file when a change to the default is desired. If port 4173 is React's default, it might not be in a config file at all.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.