This expander can be best used for user generated content validation together with other tools.
![tinyurl expander tinyurl expander](https://farm9.staticflickr.com/8770/17191771258_5d10555fb3.jpg)
#Tinyurl expander code#
You can easily adapt the code above to work with your specific use case, but if you want a ready-made and easy to use URL-unshortener NPM library you can trust a library I recently published called tall. A Promise-based, dependency free, Node.js library for expanding short URLs In case we are not dealing with a short URL, this script will print back the original URL passed to the function. By doing so we have an opportunity to catch a redirect response in our callback and so we can read its Location header which will represent the expanded URL. By default, this library follows redirects so we need to explicitly disable this behaviour by specifying the option followRedirect: false. Var request = require ( 'request' ) var uri = '' request ( )įor simplicity, in this script, we are using the request module to perform the HTTP request. Now that we know how short URL services work, it shouldn’t be hard to create a Node.js script that is capable of resolving any type of short URL. Simple enough, right? Resolving short URLs in Node.js This is what happens when a user through a browser deals with a short URL, everything happens behind the scenes and the user won’t even notice that there was an exchange with a short URL server.
![tinyurl expander tinyurl expander](https://cdn.shopify.com/s/files/1/0089/9167/0335/products/IK101_5.png)