-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (28 loc) · 768 Bytes
/
index.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const app = express();
require('dotenv').config();
const path = require('path');
const URL = require('./models/url');
const {PORT} = process.env;
//db connection
require('./dbConnection').dbConnection();
//ejs
app.set('view engine', 'ejs');
app.set("views", path.resolve("./views"))
//middlewares
app.use(express.json());
app.use(express.urlencoded({extended : true}));
//routers
const urlRouter = require('./routes/url')
app.use('/api/v1/url', urlRouter);
app.use('/api/v1/url/:shortUrl', urlRouter);
app.get('/', async (req,res)=>{
const allUrl = await URL.find({})
return res.render('index', {
allUrl : allUrl,
PORT : PORT
})
})
app.listen(PORT, ()=>{
console.log(`server is running at port ${PORT}`);
})