0

I've installed an enterprise application that runs primarily on Node.js for serving data. It is an appliance on a CentOS box. It has many different node.js applications running at the same time on different ports. For example, there is an admin page that runs on port 4000, a user dashboard that runs on 4200, etc. This is note-worthy because I am injecting new API endpoints into the server files to serve additional data to the user. To avoid CORS, I need to serve the data from the same port that the user is currently accessing (using JSONP is annoying and unreliable for IE).

Basically I need to find the primary server.js file (or what ever it may be named) that is serving data on port 4000. I've tried a simple text match of json/js files using grep --include=*.{js,json} -rw '/folderWhereAppRuns' -e "4000" but that brings back way too many files to sift through. A similar search for "express()" brings back primarily the node-module files for express dependencies.

So I found the PID of the process running on port 4000 and plugged it into pwdx, but this just brings back the root directory of where I would expect the server file to be located. There are so many subfolders within this directory though, that it doesn't do me much good. I want to know the exact location and filename of the server file.

mjoyce91
  • 316
  • 2
  • 19
  • I think, you're looking for this: http://stackoverflow.com/questions/13129464/how-to-find-out-which-node-js-pid-is-running-on-which-port – Adam Jan 25 '16 at 14:56
  • @Adam - I don't want to kill the process, I want to find the exact filepath of where the server file originated from. – mjoyce91 Jan 25 '16 at 14:59

1 Answers1

1

You should run this first:

netstat -anp 2> /dev/null | grep :4000 | egrep -o "[0-9]+/node" | cut -d'/' -f1

you'll get the pid from it then you run:

ps -p $PID -o command
Adam
  • 4,985
  • 2
  • 29
  • 61