Backend UrlShortener Questions

Backend UrlShortener Questions
0

#1

Hello! After doing the UrlShortener project I still have some unanswered questions and would be glad if anyone can enlighten me, thanks!

  1. Mongodb is not required to complete this project right? (I initially thought it was needed and just followed other campers lead)
  2. Is it possible to have a json response that contains links? (e.g. a href) If so how? As you can see from my version of the project, since I don’t know how to create links from json, instead rendered a jade page for results.
  3. Is it possible to add for instance www.google.com behind the original url instead of http://google.com or https://google.com? From what I found it just combines the whole url into one and a 404/error is obviously returned.
  4. I realised that jade has been deprecated and named pug. But as far as I am concerned it still works, is still downloaded, and on the npm page it is still up. So deprecation can just be ignored?
    https://secure-ridge-541.herokuapp.com/
    https://github.com/JstAnther1/freecodecamp-Backend-UrlShortener-P3

Thanks!!!


#2

I guess you could do it in an array or map, but you are just delaying the inevitable. Eventually, you will have to learn MongoDB - you might as well start on an easier project.

Not really, JSON stores string value pairs. Also, this is missing the point of JSON and API’s. The idea of an API is to send data from a server to a client. It is expected that the client will parse the JSON and create a link. People who are using your URL shortener API as an API do not care if it is a link as they want the data, not interactivity. If you really want to have it with a link, my suggestion is to create separate endpoints. One for general users who want a link - send them a rendered fancy page (not a page that fakes a JSON look). For an API endpoint, send them actual JSON data, not a rendered HTML page. Just an idea.

Firstly, you should be validating the URL to make sure it works (try npm validator). Not all websites have a www in front of their name, so you can’t just remove a http or https and put in a www. You should be fine removing the http or https, you can do so with some regex: url.replace(/^.*:\/\//i, ''). Then you would have just google.com or www.google.com.

From Pug itself:

If your package or app currently uses jade, don’t worry: we have secured permissions to continue to occupy that package name, although all new versions will be released under pug … if you are new to Pug, you should get started with the new syntax and install the Pug package on npm.

I would suggest using the official new release. It has the latest features and bug fixes. I don’t think it is that huge of a change, why not just update to the new package?