-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (24 loc) · 676 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (24 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const express = require("express");
const urlroute = require("./routes/url")
const {connect} = require("./connectdb")
const URL = require("./models/url")
const app = express();
connect("mongodb://localhost:27017/short-url").then(()=>{
console.log("Database is Connected");
})
app.use(express.json())
app.use("/url", urlroute)
app.get("/:shortid",async(req,res)=>{
const shortid = req.params.shortid;
const entry = await URL.findOneAndUpdate({
shortid
},{$push:{
visithis :{
timestamp : Date.now(),
}
}})
res.redirect(entry.redirectURL);
})
app.listen('8000',()=>{
console.log("Server Started at Port 8000");
})