Giter VIP home page Giter VIP logo

node-url-shortener's Introduction

Node Url Shortener

A modern, minimalist, and lightweight URL shortener using Node.js and Redis.

Build Status GitHub tag Dependency Status

Using

Quick Start

$ git clone [email protected]:dotzero/node-url-shortener.git
$ cd nus
$ npm install
$ node app

Command Line Options

$ node app -h

Usage: app [options]

Options:
  -u, --url     Application URL               [default: "http://127.0.0.1:3000"]
  -p, --port    Port number for the Express application          [default: 3000]
  --redis-host  Redis Server hostname                     [default: "localhost"]
  --redis-port  Redis Server port number                         [default: 6379]
  --redis-pass  Redis Server password                           [default: false]
  --redis-db    Redis DB index                                      [default: 0]
  -h, --help    Show help                                              [boolean]

Installation on production

$ git clone [email protected]:dotzero/node-url-shortener.git nus
$ cd nus
$ npm install --production
$ NODE_ENV=production node app --url "http://example.com"

RESTful API

POST /api/v1/shorten with form data long_url=http://google.com, start_date="", end_date="", c_new=false.

NOTE: You can send the post requests without the date and c_new params

POST /api/v1/shorten with form data long_url=http://google.com, start_date="2017/06/19", end_date="2017/06/20", c_new=true

The c_new paramter is do that it creates a new short url if one already exists for the url

{
  "hash": "rnRu",
  "long_url": "http://google.com",
  "short_url": "http://127.0.0.1:3000/rnRu",
  "status_code": 200,
  "status_txt": "OK"
}

GET /api/v1/expand/:hash with query rnRu

{
    "start_date": "undefined",
    "end_date": "undefined",
    "hash": "rnRu",
    "long_url": "http://127.0.0.1:3000/rnRu",
    "clicks": "0",
    "status_code": 200,
    "status_txt": "OK"
}

OR if dates are set

{
    "start_date": "2017/06/19",
    "end_date": "2017/06/20",
    "hash": "rnRu",
    "long_url": "http://127.0.0.1:3000/rnRu",
    "clicks": "0",
    "status_code": 200,
    "status_txt": "OK"
}

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

Released under the MIT license

node-url-shortener's People

Contributors

dotzero avatar preciousgeorge avatar dmitry-kucher avatar typpo avatar matteocontrini avatar thesimkin avatar teebot avatar

Watchers

James Cloos avatar Nathanial Myers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.