Hello! After doing the UrlShortener project I still have some unanswered questions and would be glad if anyone can enlighten me, thanks!
Mongodb is not required to complete this project right? (I initially thought it was needed and just followed other campers lead)
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.
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?