I am developing a dashboard, I need to conect to a API and catch a Auth Token and afther that send info by using a HTTPS protocol. I use a Nodejs, and when I run my code I have the next error on the pm2 monit:
Error: getaddrinfo ENOTFOUND my.url.net/pathat GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {errno: -3008,code: 'ENOTFOUND',syscall: 'getaddrinfo',hostname: 'my.url.net/path'}
Also here is my code where I made the request (Node.js):
const path = require('path');require('dotenv').config({path: path.join('path','.env')});const https = require('https');const database = require('./sql');const fs = require ('fs');const user = process.env.USER;const pwd = PWD;const host = 'https://my.url.net/extencio';const host_1 = 'my.url.net/extention';async function getLoginToken(pForce){ if (login_token.Health && !pForce) { return login_token } //Creates the POST request const options = { protocol: 'https:', hostname: host_1, path: '/api/auth/token', method: 'POST', headers: {'Accept': 'application/json','Content-Type': 'application/json', } }; //Body of the POST request, contains the user and password const post_data = JSON.stringify({username: user, password: pwd});
.Here is the rest of the code:
return new Promise((resolve, reject) => { const req = new https.request(options, (response) => { response.setEncoding('utf8'); response.on('data', function(chunk){ const output = JSON.parse(chunk); if(output.token){ login_token.Health = true; login_token.Token = output.token; resolve(login_token) } else{ login_token.Health = false; login_token.Token = ''; resolve(login_token); } }); }); req.write(post_data); req.end(); req.on('error', function(err) { console.log(err); login_token.Health = false; login_token.Token = ''; resolve(login_token) }); });}