node.js生成二维码

var http = require('http');
var qs = require('querystring');
var qrImg = require('qr-image');



var server = http.createServer(function (request, response) {
    console.log('');
    console.log((new Date()).toLocaleString());
    console.log(request.url);
    
    var query = require('url').parse(request.url).query;
    var params = qs.parse(query);
   
    var string_url = 'http://www.baidu.com';
    var img = qrImg.image(string_url, { size: 10 });
    response.writeHead(200, { 'Content-Type': 'image/png' });
    img.pipe(response);
});

server.listen(8080, function () {
    console.log('申请二维码端口:' + 8080);
});

运行完,本地访问就可以看到

转载于:https://www.cnblogs.com/maomingchao/p/9395740.html

你可能感兴趣的:(node.js生成二维码)