How to specify a network interface when making net requests from Node.js?

http, network-interface, node.js, tcp

Solution

Node has this built in:

http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener

http://nodejs.org/api/http.html#http_http_request_options_callback

See `localAddress`, just set that to the IP of the interface you'd like to use.

Problem

In either `http.request` or `net.connect`, is there an option that I can specify a network interface to initiate a connection? EDIT: AFAIK in OS level I can specify address level, or load balancing into routing tables. But the way of interface choosing in my software is more than that, I wanna know if I can do that in codes.

Original source