By : bguiz Published On Thursday, September 25, 2014, 02:43 In JavaScript
Run your own URL shortening service, or integrate one into your existing NodeJs servers.
This is a pure server-side module. URL shortify
A NodeJs server that allows you to run a simple URL shortening server.
jade-templates/, and they will be automatically compiledpage-templates.js, and this module exports template functions whose names match the Jade filesFirst, install some prerequisites:
v0.10.29 && < v0.11.x
v2.8.16 && < v3.0.x
make, set up Redis as a service:
cd utils && sudo ./install_server.shopenssl list-message-digest-algorithms and ensure that MD5 is availableNext, 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.
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.
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.
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;
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.
Please let me know in the Comments section for this item.
This module is available dual licenced under
As such, this module is not available from the npm registry.
Instead of npm installing 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.
Brendan Graetz