VPN (usually) tunnel layer 2 or 3 network packets through a specific channel. From the point of view of the application level, you do not need to worry about the lower levels, since the routing of network packets is performed by the OS. OpenVPN, for example, creates a virtual TUN or TAP interface and transmits all packets sent by the OS to these interfaces through a secure tunnel. A solution whose interface to use is implemented with respect to the routing table. A web proxy server is much simpler than a VPN because it simply accepts HTTP requests (application layer) and passes them.
It really depends on which VPN you are using. Suppose you are using OpenVPN and it creates a virtual interface for you (for example, tun0 ), this interface has its own IP address (for example, 10.124.1.6 ) and possibly (depending on the topology server) a P2P address (for example, 10.124.1.5 ). You can tell Node to connect network connections through a specific (local) network interface using localAdress :
var options = { host: "example.com", path: "/path/to/web/service", localAddress: '10.124.1.6',
Hypothetically, this will be the solution to selective tunneling of specific requests through the VPN interface. If it works or not , I can not guarantee. But I would say that you will start with some ideas.
source share