Function not found error while running locally using netlify dev

Netlify deploys over cloud work as expected:

deploy

netlify dev command output:

nd

But on my computer, netlify dev command gives port 3999 for frontend which fails to connect to functions port since they run on random 5xxx port, while my JavaScript code assumes frontend port 3999 (which works well when deployed)

local 3999

My Javascript code:

local js script

On my computer netlify dev commands lambda server port (5xxx) serves the functions as expected:

local functions

My directory structure:

dir str

In short lambda server port and frontend port is different thus function not found is received for frontend function requests

To answer your question exactly: No, I am connecting lambda server port from the frontend. I would never know lambda server port since netlify dev gives random generated lambda server port

Please help me get the functions working together with frontend on my computer with netlify dev command