Back End Development and APIs Projects - URL Shortener Microservice

Tell us what’s happening:
dns.lookup doesn’t work when i get the hostname from the url - it accepts all kinds of strings as valid hostnames. When i test manually with a string containing ‘example’ it works.

Your project link(s)

solution: boilerplate-project-urlshortener - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15

Challenge: Back End Development and APIs Projects - URL Shortener Microservice

Link to the challenge:

Not sure what you mean.

I notice no matter what url I submit to your app, the short_url property value is always 1 in the returned JSON. For each unique url, it should change. Also, I am not your why you have other properties in the returned JSON besides the required ones.

Also, you should be using a persistent data source to store the urls in. Everytime you restart the server, the global variable resets back to an empty object and you lose all the urls submitted to it. That is not a practical application.

url.parse is deprecated. Use the URL constructor instead (WHATWG URL API).

const url = require('url');
const dns = require("dns");

const nodeURL = url.parse('ftp:/john-doe.invalidTLD').hostname;
const WHATWG_URL = new URL('ftp:/john-doe.invalidTLD').hostname

console.log(nodeURL) // null
console.log(WHATWG_URL) // ftp:/john-doe.invalidTLD


dns.lookup(nodeURL, (error, address, family) => {
  if (error) {
    console.error(error);
  } else {
    console.error('No error'); // No error
  }
});