Run your personal URL shortening service, or combine one into your present NodeJs servers.

This can be a pure server-aspect module.
URL shortify

README.md

A NodeJs server that lets you run a easy URL shortening server.

Options

  • Consumer can submit a full URL and obtain a brief URL
  • When visiting a brief URL, consumer will get redirected to the lengthy URL
  • If similar URL is shortened a number of occasions, the brief URL will get re-used
  • Extraordinarily quick shortening and lengthening
    • Specifics for the algorithms nerds:
      • O(1) time complexity for each insert and lookup
      • O(N) area complexity
  • Simply prolonged, designed with flexibility in thoughts
    • No dependence on frameworks, reminiscent of categorical
    • As an alternative exposes a low degree NodeJs HTTP deal with perform, which may be consumed by most NodeJs frameworks
    • Every function is cut up into its personal handler perform, in case you want to combine and match by yourself
  • Straightforward and versatile templating
    • Out of the field help for Jade templates
      • Simply put them in jade-templates/, and they are going to be mechanically compiled
      • Merely require web page-templates.js, and this module exports template features whose names match the Jade information
    • That is utterly non-compulsory, and you need to use your personal most popular engine

Establishing

First, set up some conditions:

  • NodeJs and npm.
  • Redis.
    • You must use Redis >= v2.eight.sixteen && < v3.zero.x
    • Comply with instructions here.
    • On Ubuntu/ Debian methods, after make, arrange Redis as a service:
      • cd utils && sudo ./install_server.sh
  • OpenSSL.
    • Must be preloaded on most techniques, in any other case, comply with instructions here.
    • Run openssl listing-message-digest-algorithms and be sure that MD5 is on the market

Subsequent, within the folder the place you’ve got this module put in, run:

npm set up
node run begin

Lastly, go to http://0.0.0.0:8080/ in your browser,
and you ought to be prompted with the primary web page, the place you’ll be able to shorten your first URL.

Superior utilization

Say you have already got your personal NodeJs server,
and you don’t want to exchange it with this one,
however quite merely deal with a couple of additional routes for URL shortening.
That’s definitely attainable.

cp urlshortify $EXISTING_PROJECT/node_modules/
#edit $EXISTING_PROJECT/package deal.json to incorporate "urlshortify" in dependencies

Word that as a result of this module is personal,
because it must be distributed utilizing Envato’s market.
it’s not distributed utilizing npm.
npm set up --save urlshortify will not work.
Thus it’s essential set up it manually utilizing the steps above.

For all options

Should you want to embrace all options,
you need to use the primary handler perform by requiring it:

var urlshortify = require('urlshortify');

Use server.js as a reference.

For particular person options

Alternatively, you should use the person handler features,
should you want to compose your routes with a better degree of specificity:

var urlshortifyLengthen = require('urlshortify').lengthen;

Configuration

Edit config-settings.js to vary the settings in your URL shortener.
The settings are defined inline in feedback.

Once you begin the server, examine the console output.
It ought to print out a the configuration object, just like:

config  hostname: '10.1.1.1',
  port: '8080',
  isDebug: true,
  hashIdSalt: 'hashids salt',
  minLength: 6,
  startingCounter: zero,
  assumeProtocol: 'http' 

It’s strongly beneficial that once you deploy the app to manufacturing,
you must change your hostname to the area which you’re deploying to,
the port to eighty,
and the hash salt to one thing aside from the default worth.
The default values for the opposite configuration settings could also be left as is for manufacturing.

Word that when deployed to manufacturing,
you must by no means change the worth of the hash salt,
until you’re prepared to invalidate all URLs which were shortened prior.

Points/ Requests

Please let me know within the Feedback part for this merchandise.

Licence

This module is accessible twin licenced beneath

As such, this module is not out there from the npm registry.
As an alternative of npm set uping this, you should copy the folder to the suitable location.

Please buy the common licence in the event you want to use this in a single software for a single shopper,
and buy the prolonged licence for those who want to use this in a number of purposes or for a number of shoppers.
Learn the complete particulars of the licences from the pages above.

Writer

Brendan Graetz