Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect VPN using nodejs in ubuntu

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!!!

like image 572
Profer Avatar asked Apr 01 '19 06:04

Profer


1 Answers

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

like image 73
Sachin Shah Avatar answered Sep 21 '22 15:09

Sachin Shah