-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (35 loc) · 957 Bytes
/
Copy pathindex.js
File metadata and controls
44 lines (35 loc) · 957 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
37
38
39
40
41
42
43
44
const express = require('express');
const bodyParser = require('body-parser');
const qr_code = require('qrcode');
const app = express();
app.set('view engine','ejs');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.get('/', function(req, res){
res.render('index',{QR_code:''});
});
app.post('/', function(req, res){
const url = req.body.url;
console.log(url);
if(url){
qr_code.toDataURL(url, function(err, src){
if(err){res.send(err); console.log(err);}
var file_path = "store/"+ Date.now() +".png";
qr_code.toFile(file_path,url, {
color: {
dark: '#000', // Black dots
light: '#0000' // Transparent background
}
});
res.render('index',{QR_code:src,img_src:file_path});
});
}else{
res.send('URL Not Set!');
}
});
app.get('/download',function(req,res){
res.download(req.query.file_path);
})
app.listen(3000,function(){
console.log('Server listing on 3000');
});