12

I have the code in my nodejs file which gives me the following information

host:"147.0.40.145"
method:"aes-256-cfb"
password:"9c359ad1ebeec200"
port:38473

I need to use above information and want to connect VPN through it. I have used below code to extract the above information.

const connectServer = (serverId) => {
  const token = store('access_token')
  httpOptions.Authorization = token.token_type+' '+token.access_token
  return new Promise((resolve, reject) => {  
   const response = await axios.post(`${baseUrl}/servers/${serverId}/connect`, {'serverId':serverId},{headers: httpOptions})     
   console.log(response.data)
    resolve(response.data)
  })
}

So I need to know whether it is possible using nodejs to connect or create VPN?

Thank you in advance!!!

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21
Profer
  • 553
  • 8
  • 40
  • 81
  • Related (to connecting to VPNs in Node.js, not promises): https://stackoverflow.com/questions/32048832/node-js-programmatically-connect-to-a-vpn-or-route-http-requests-via-vpn – T.J. Crowder Apr 01 '19 at 07:18
  • 1
    I have no idea. It would probably help if you added more detail. What kind of VPN, what errors you get, etc. – T.J. Crowder Apr 02 '19 at 09:45
  • @T.J.Crowder Sorry but I could not find either code or any solution on the google for this. Even I do not know whether it is possible or not ***connect VPN using nodejs*** . The above code is just used to extract the information needed for connecting VPN. **:-(** – Profer Apr 02 '19 at 09:48
  • I believe it is explained here - https://stackoverflow.com/questions/43240483/axios-https-request-over-proxy – Eternal1 Apr 03 '19 at 10:06
  • @Eternal1 There is nothing in the link regarding the above question – Profer Apr 03 '19 at 10:12
  • which ubuntu version you are using? – Vikas Yadav Apr 09 '19 at 08:36
  • @VikasYadav I am using **16.04** – Profer Apr 09 '19 at 09:38
  • You really need to provide more information and a better example. What type of VPN are attempting to connect to (OpenVPN, IPSEC, etc)? Why did you include the privoxy tag? What does it have to with this question? I fail to see how the code you posted is related to the question. – Ben Apr 09 '19 at 16:14

1 Answers1

12

Install this npm

npm i node-openvpn --save

const openvpnmanager = require('node-openvpn');

const opts = {
  host: '147.0.40.145',
  port: 38473,
  timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
  logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
const auth = {
  user: '{{add user name}}',
  pass: '9c359ad1ebeec200',
};
const openvpn = openvpnmanager.connect(opts)


 openvpn.on('connected', () => {
   console.log("Connected to VPN successfully...");
 });

For more info , please read this link

Another option Link

Sachin Shah
  • 4,503
  • 3
  • 23
  • 50