Skip to content

Commit

Permalink
Init commit with functioning shortening of url and vice-versa
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishkarki committed Mar 21, 2021
0 parents commit 5cd516c
Show file tree
Hide file tree
Showing 27 changed files with 43,068 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
url-shortener-web\node_modules

config/development.json
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Full stack app to facilitate the shortening of long urls.

## More details to be added.
25 changes: 25 additions & 0 deletions config/db-connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const colors = require('colors')
const mongoose = require('mongoose')
const config = require('config')

const MONGO_URI = config.get('mongoUri')

const connectToDB = async () => {
try {
const conn = await mongoose.connect(
MONGO_URI,
{
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
}
)

console.log(`Mongo Atlas connected: ${ conn.connection.host }`.magenta.underline.bold)
} catch (error) {
console.log(`There was an error ${ error.message }`.red.bgWhite.bold)
process.exit(1)
}
}

module.exports = connectToDB
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:5000",
"mongoUri": ""
}
20 changes: 20 additions & 0 deletions models/Url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose')
const { nanoid } = require('nanoid')

const UrlSchema = new mongoose.Schema({
longUrl: {
type: String,
required: true,
},
// shortUrl: { // baseUrl + urlId
// type: String,
// required: true,
// },
urlId: {
type: String,
required: true,
default: nanoid(10),
},
})

module.exports = mongoose.model('Url', UrlSchema)
Loading

0 comments on commit 5cd516c

Please sign in to comment.