最近在学node,就想着node能不能像后台那样生成邮件,结果找到了qr-image这个生成二维码的插件。
代码:
qr.js
var qr = require('qr-image')
var app = require('express')()
app.get('/',function(req,res){
var code = qr.image('点开就是承认伍猪猪是只臭猪',{type:'png'})
res.sendFile(__dirname+'/index.html')
code.pipe(res);
})
app.listen(3000,function(){
console.log('启动啦')
})
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<img src="/qr" alt="qrcode">
</body>
</html>
在命令行运行node qr.js之后,打开localhost:3000就得到扫描二维码页面