Git Product home page Git Product logo

abhi5658 / node-mongo-url-shortner Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 229 KB

Try it. (Just to be good, don't fill it up). URL does not work anymore. Do not have paid plan of Heroku

Home Page: https://short-url-abhi.herokuapp.com/

JavaScript 61.45% EJS 38.55%
shorturl bootstrap node mongo mongodb mongoose express express-js middleware shortid ejs dotenv env heroku heroku-deployment heroku-app heroku-cli short url shortner

node-mongo-url-shortner's Introduction

node-mongo-url-shortner

Steps involved:

  • npm init -y
  • npm i express mongoose ejs
  • npm i --save-dev nodemon
  • create server.js
  • start script for dev in "scripts"
  • serve root at localhost:5000
  • npm run start-dev -> executes: nodemon server.js
  • create views directory
  • create index.ejs -> create basic html -> add form, table -> run
  • add bootstrap cdn -> apply bootstrap to form, table -> run
  • create directory models for storing db models
  • create short_url.js and create schema for urls collection
  • create mongodb connection in server.js -> run check
  • npm i shortid creates unique short identifier
  • add shortid property in schema
  • add app.use for express urlencode
  • create POST /shortUrls route for taking in URL requests
  • create new object in post request and then redirect -> run
  • add find all short urls in serving root and pass as parameter to index file
  • use shortUrls obejct to fill table to show urls from server -> run
  • create new route for redirecting shortUrl at end of server.js
  • find url based on shortUrl, add click, save, redirect if not null -> run
  • create error page in views
  • when short url does not exist, render error with response
  • added app use to send response 204 for favicon request and shifted route log below this
  • install dotenv npm i dotenv
  • create .env file for storing db credentials
  • provide arguments to database call using process.env.VARIABLE_NAME
  • issue faced: whenever username used as a env variable, when invoked gave first letter capital of corresponding value. e.g. admin -> Admin
  • :: hence using user in this case in environment variables

Begins heroku deployment:

  • create heroku account
  • install heroku CLI
  • goto local project git directory
  • login into heroku cli : heroku login
  • enter credentials -> login success
  • heroku starts server on port 5000! the code has been designed to accept port from external environment
  • create heroku project: heroku create app_name : heroku create short-url-abhi : this creates a git project named short-url-abhi assosiated to heroku
  • goto heroku dashboard -> app -> settings -> config vars : add .env variables
  • push commited project to heroku master branch : git push heroku master : makes the project live at returned url

node-mongo-url-shortner's People

Contributors

dependabot[bot] avatar

Watchers

 avatar  avatar

Forkers

k4stats

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.