Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[CAP] BAS – port 4004 is already in use by another server process

If the default port 4004 is already open and you want to see what is bound to it, select View -> Find Command -> Ports Preview

Solution to kill another “watch.js” process using/blocking the port: https://answers.sap.com/questions/13016130/sap-business-application-studio-stop-running-serve.html
To archive the same in a single command use:

lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep watch.js | awk '{print $2}')

As alternative, change the default port by adding a new port in package.json to the start script, for example: “start”: “cds run –port 4003” and use npm run start instead of cds watch.


Update 20.02.2023: Just had the problem again due to a VPN disconnect. But this time I had an application running using cds run. Therefore, I had to change the command from watch.js to cds.js:

lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep cds.js | awk '{print $2}')

Update 10.05.2023: A better approach seems to be killing the node process. This should work in both situation.

lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep node | awk '{print $2}')

Update 29.02.2024: With the BAS migration to Code – OSS the previous commands were not working anymore, but this new command seems to work:

kill -9 $(ps aux | grep cds.js | awk '{print $2}')
# or
kill -9 $(ps aux | grep cds-dk | awk '{print $2}')