DEV Community

Cover image for Building a URL shortening service with NodeJS and MongoDB. Deploy to Azure.

Building a URL shortening service with NodeJS and MongoDB. Deploy to Azure.

Olamide Aboyeji on April 15, 2020

Hey there, we would be building a URL shortening service with NodeJS, Express, and MongoDB. We would then go ahead and deploy our web application t...
Collapse
 
andersonpimentel profile image
Anderson Pimentel

Great article! Congrats!

Two minor fixes:

  • On package.json file, it's missing a comma at the end of the line:
"dev" : "nodemon server.js"
  • On server.js there's an extra s on body-pa*s*rser
Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Thanks for pointing that out. Fixed.

Thank you

Collapse
 
petermezes profile image
Peter Mézeš

Nice one, thank you!

Btw, that error handling:

catch (error) {
        ///catch any error, and return server error
        return res.status(500).json({ok : false, error : 'Server error'});
}

It is like programming version of: - What is wrong darling? - Nothing!

All good, just made me giggle a bit :)

Collapse
 
emindeniz99 profile image
Emin Deniz

👏🏼 Good project

I can’t understand why you are storing “shorturl” and “ uniquename”, shorturl consist of baseurl and uniqueurl
It can be generated dynamically when execution of geturl, because baseurl is constant for all links, no need to store it.
Also, if we change the domain, it can be used still

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

The problem happens to be having to buy a short domain, to get a short URL.

Collapse
 
emindeniz99 profile image
Emin Deniz

Sometimes it is not necessary. At my student club, we are using rebrandly with subdomain of our website. example go.compec.org/xyz
It seems long, but easier than bit.ly or tinyurl. Domain part of short url includes “go” and our club short name.
We are happy with it.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Actually, xxx.now.sh seems shorter (with splat / regex), but I don't how short xxx can be.

Also, now.sh supports database via /api folder (or serverless / buildpacks). I should try to make a url shortener someday, perhaps...

Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Yes, you would have to set that up on the azure portal. Buy one and configure.

Collapse
 
sammychinedu2ky profile image
sammychinedu2ky

Nice one bro

Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Thanks

Collapse
 
jopo79 profile image
Javier Fernández

Good Job!!

Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Thank you

Collapse
 
louisnel profile image
Louis Nel

Loved this tutorial. The hardest part seems to find a cool short URL. The use of the fetch library in the frontend seems leaner than using jQuery AJAX.

Collapse
 
vicradon profile image
Osinachi Chukwujama

The short url is long

😄

Nice article. Though we'd need to make your Frontend more appealing.

Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Thank you!
Yes, you would have to get a short domain name and map it to the azure app.

For the frontend 😅, did not want to spend time on UI, just straight to implementation.

Collapse
 
blgguy profile image
Aminu M. Bulangu

Awesome

Collapse
 
olamideaboyeji profile image
Olamide Aboyeji

Thank you