npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-url-shortener-ts

v1.1.1

Published

Simple Node URL shortener

Downloads

1

Readme

Node URL Shortener

This is the actual 'URL Shortener' part of the project. This runs a RESTful API that posts new shorten links and gets websites.

Install and run

  1. First install Mongo and Node.

2.a If you are installing this through npm use.

npm start

2.b Run the next lines after cloning the project:

$ cd ./url-shortener/backend
$ npm install
$ npm start

Using the API

The API is used through standard http requests. This are the expected results from get and post requests.

URL | GET | POST --- | --- | ---- http://youraddress/sites | List of elements in the collection 'sites'. | Adds an element to sites collection and returns status of transaction and inserted element or reason of failure. http://youraddress/azb091 | Redirects to website if successful, if not then returns a 404. | No POST request for /:code.

Command line options

Usage url-shortener: node index options arguments Options:

Command | Action ------- | ------ -h, --help | Prints all of the command line options -p, --port [port number] | Sets port name of the node server (3000 by default) --mongo-db [mongo collection name] | Sets the mongo collection ('short' by default) --mongo-host [mongo hostname] | Sets the hostname where mongoDB is (localhost by default) --mongo-port [mongo port] | Sets the port where mongoDB is (27017 by default)

Understading the code

Everything is written in Typescript but there is no need to sweat it with compiling, just run npm run build or tsc on this directory and the code will be built production ready on the dist folder. And if you want to live-run use npm start.

Project structure

The source code is on the src folder and the build is in the dist folder. App.ts has the actual server and index.ts is where the server is run.

  • src: Project source code (typescrypt)
  • dist: Built code (javascript)

Code

Initiating the server (In index.ts)

import app from './App'

const port = process.env.PORT || 3000

app.listen(port, (err) => {
  if (err) {
    return console.log(err);
  }
  return console.log(`Server is listening on ${port}`);
});

The rest of the application
The rest of the application is in App.ts