-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (25 loc) · 847 Bytes
/
index.js
File metadata and controls
36 lines (25 loc) · 847 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
30
31
32
33
34
35
36
const express = require('express');
const bodyParser = require('body-parser');
const qrCodeGenerator = require('./qrCodeGenerator');
// Creating app
const app = express();
// USing ejs view
app.set("view engine", "ejs");
// USing body parser to get data form dom
app.use(bodyParser.urlencoded({extended:true}))
app.get('/', (req, res) => {
res.render("index", {qrImgPath:'', errorMsg:''});
});
// Post request
app.post("/", async (req, res)=>{
const inputUrl = req.body.url.trim();
if(!inputUrl){
return res.render("index", {qrImgPath:'', errorMsg:'Invalid Input'})
}
const qrImgPath = await qrCodeGenerator(inputUrl);
res.render("index", {qrImgPath:qrImgPath, errorMsg:''})
});
// Listening port or Starting sever
app.listen(process.env.PORT || 3000, ()=>{
console.log(`Server is Running.`);
});