Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify client port Node js request

Tags:

http

node.js

Sending a request from NodeJs, I want to specify the starting port, for example:
request to google.com port 80
from port 52000.
So the connection will be from from port 52000 to 80. My goal is to bootstrap a web server under a NAT, but I'm not allowed to set the forwarding port on the NAT itself.
How can I perform it? Thank you!!

like image 973
Fucio Avatar asked Nov 22 '25 13:11

Fucio


1 Answers

In the official node documentation (which I advise you to check), you have a localAddress and localPort properties, which you can use to bind to them before connecting to a remote socket.

That's the lowest level. Node HTTP requests expose the socket, so you can use it to access those properties, or you can write your own HTTP requester with basic nodejs sockets.

like image 144
Jorge Fuentes González Avatar answered Nov 24 '25 05:11

Jorge Fuentes González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!