Follow URL Redirects with Node.js

C

codeguru

Member
Freecoin
295
URL shorteners are a dime a dozen these days, and it is quite nice to have a pretty URL instead of a mile long string, but there are some downsides to URL shorteners: they can mask dangerous URLs and getting to the endpoint can be slow, since you end up making multiple requests. And what if a shortener sold out to a porn company?! Whoa!

A while back I wrote a post about following URLs from command line with cURL. Since I love JavaScript and Node.js is in full flight, I want to show you linkfollower, a Node.js utility for following URL redirects and getting the final landing URL.

Start by installing linkfollower:


yarn add linkfollower
# or `npm install linkfollower`


With linkfollower installed globally, we can use the follow command to follow the series of redirects until the final URL:


# follow {url}
follow http://davidwalsh.name/css

# RESULT:
# http://davidwalsh.name/css -> 301
# https://davidwalsh.name/css -> 301
# https://davidwalsh.name/css-animation-callback -> 200


URL shorteners can be likened to a blindfold — the promise of going one place but possible end up in another. Using linkfollower is a good practice if you care to be secure with links.

The post Follow URL Redirects with Node.js appeared first on David Walsh Blog.



Continue reading...
 

Richest Freecoded User

Most Freecoin

freecoded
freecoded
2,436 Freecoin
Davy200
Davy200
590 Freecoin
nathan69
nathan69
424 Freecoin
Laureine
Laureine
415 Freecoin
C
codeguru
295 Freecoin
Tekera
Tekera
263 Freecoin
R
ruthailand
221 Freecoin
A
Akubay
170 Freecoin
smitha
smitha
104 Freecoin
G
Gabby
93 Freecoin
Top