Hi everyone. I’m on the URL shortener project and although I have already a vague idea on how to validate the urls and randomly generate a short one, how am I supposed to really generate a link that, say, redirects you from shorturl.com to incrediblylong.com ? I’m completely lost on this, I know there are tons of project feedbacks but I prefer to avoid spoiling me the whole project.
Thanks in advance
Assuming you are using node and express, this should help: https://expressjs.com/en/4x/api.html#res.redirect
The express docs are very detailed… You’ll need to read them a lot as you learn backend!
Oh, so the idea is having, for example, www.myprojecturl.com/longurl redirect to www.myproject.com/shorturl? Through a redirect?
Yeah, you have to store both urls in a database. When someone visits /short your express router then goes and looks for that in your DB and redirects to the /long that is associated with it.
1 Like
Oh I see now. It makes sense after the mongoDB chapter, thanks a lot!