Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhi5658/node-mongo-url-shortner
Try it. (Just to be good, don't fill it up). URL does not work anymore. Do not have paid plan of Heroku
https://github.com/abhi5658/node-mongo-url-shortner
bootstrap dotenv ejs env express express-js heroku heroku-app heroku-cli heroku-deployment middleware mongo mongodb mongoose node short shortid shortner shorturl url
Last synced: 2 days ago
JSON representation
Try it. (Just to be good, don't fill it up). URL does not work anymore. Do not have paid plan of Heroku
- Host: GitHub
- URL: https://github.com/abhi5658/node-mongo-url-shortner
- Owner: abhi5658
- Created: 2020-03-09T06:43:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T06:24:38.000Z (over 1 year ago)
- Last Synced: 2024-05-01T15:45:52.188Z (7 months ago)
- Topics: bootstrap, dotenv, ejs, env, express, express-js, heroku, heroku-app, heroku-cli, heroku-deployment, middleware, mongo, mongodb, mongoose, node, short, shortid, shortner, shorturl, url
- Language: JavaScript
- Homepage: https://short-url-abhi.herokuapp.com/
- Size: 224 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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