Run your own URL shortening service, or integrate one into your existing NodeJs servers.
This is a pure server-side module.
URL shortify
README.md
A NodeJs server that allows you to run a simple URL shortening server.
Features
- User can submit a full URL and receive a short URL
- When visiting a short URL, user gets redirected to the long URL
- If same URL is shortened multiple times, the short URL gets re-used
- Extremely fast shortening and lengthening
- Specifics for the algorithms nerds:
- O(1) time complexity for both insert and lookup
- O(N) space complexity
- Specifics for the algorithms nerds:
- Easily extended, designed with flexibility in mind
- No dependence on frameworks, such as express
- Instead exposes a low level NodeJs HTTP handle function, which can be consumed by most NodeJs frameworks
- Each feature is split into its own handler function, in case you wish to mix and match on your own
- Easy and flexible templating
- Out of the box support for Jade templates
- Just put them in
jade-templates/
, and they will be automatically compiled - Simply require
page-templates.js
, and this module exports template functions whose names match the Jade files
- Just put them in
- This is completely optional, and you can use your own preferred engine
- Out of the box support for Jade templates
Setting up
First, install some prerequisites:
- NodeJs and npm.
- You should use NodeJs >=
v0.10.29
&& <v0.11.x
- Follow instructions here.
- You should use NodeJs >=
- Redis.
- You should use Redis >=
v2.8.16
&& <v3.0.x
- Follow instructions here.
- On Ubuntu/ Debian systems, after
make
, set up Redis as a service:cd utils && sudo ./install_server.sh
- You should use Redis >=
- OpenSSL.
- Should be preloaded on most systems, otherwise, follow instructions here.
- Run
openssl list-message-digest-algorithms
and ensure that MD5 is available
Next, in the folder where you have this module installed, run:
npm install
node run start
Lastly, visit http://0.0.0.0:8080/
in your browser,
and you should be prompted with the main page, where you can shorten your first URL.
Advanced usage
Say you already have your own NodeJs server,
and you do not wish to replace it with this one,
but rather simply handle a few extra routes for URL shortening.
That is certainly possible.
cp urlshortify ${EXISTING_PROJECT}/node_modules/
#edit ${EXISTING_PROJECT}/package.json to include "urlshortify" in dependencies
Note that because this module is private
,
as it needs to be distributed using Envato’s marketplace.
it is not distributed using npm
.
npm install --save urlshortify
will not work.
Thus you need to install it manually using the steps above.
For all features
If you wish to include all features,
you can use the main handler function by requiring it:
var urlshortify = require('urlshortify');
Use server.js
as a reference.
For individual features
Alternatively, you can use the individual handler functions,
if you wish to compose your routes with a higher level of specificity:
var urlshortifyLengthen = require('urlshortify').lengthen;
Configuration
Edit config-settings.js
to change the settings for your URL shortener.
The settings are explained inline in comments.
When you start the server, check the console output.
It should print out a the configuration object, similar to:
config { hostname: '10.1.1.1',
port: '8080',
isDebug: true,
hashIdSalt: 'hashids salt',
minLength: 6,
startingCounter: 0,
assumeProtocol: 'http' }
It is strongly recommended that when you deploy the app to production,
you should change your hostname to the domain which you are deploying to,
the port to 80
,
and the hash salt to something other than the default value.
The default values for the other configuration settings may be left as is for production.
Note that once deployed to production,
you should never change the value of the hash salt,
unless you are willing to invalidate all URLs that have been shortened prior.
Issues/ Requests
Please let me know in the Comments
section for this item.
Licence
This module is available dual licenced under
- the Envato Regular Licence dated 30 April 2014
- the Envato Extended Licence dated 30 April 2014
As such, this module is not available from the npm registry.
Instead of npm install
ing this, you must copy the folder to the appropriate location.
Please purchase the regular licence if you wish to use this in a single application for a single client,
and purchase the extended licence if you wish to use this in multiple applications or for multiple clients.
Read the full details of the licences from the pages above.
Author
Brendan Graetz
- bguiz.com
- @bguiz
Kindly Note: We update new contents like WordPress Themes, Plugins, PHP Scripts everyday. But remember that you should never use this items in a commercial website. All the contents posted here for development & testing purpose only. We’re not responsible for any damage, use at your own RISK! We highly recommend to buy NodeJs URL shortener from the The Developer ( bguiz ) website. Thank you.
Download = NodeJs URL shortener-[Updated].zip