mac 下 node-qrcode的二维码库

原文出自:http://hufeng825.github.com/2013/11/27/nodejs1/


这两天在mac下折腾node.js 的二维码库 ,遇到了n多大坑. 按着其官方文档的说明只有下面简简单单几句

Dependencies

These should be taken care of for you by npm but you should...

npm install canvas
If cairo gives you trouble and you cannot install canvas, checkout the canvas site. I know @tjholowaychuk has setup a way to download and install a version of cairo/pixman for testing.

The word "QR Code" is registered trademark of:

DENSO WAVE INCORPORATED

如果你的系统是mac的话 你只按着上面的安装方法 保准你折腾的头破血流, 我就是血淋淋的例子啊.

因为mac 下其要安装的库太多了 .下面一次列出来

1. brew install  pkgconfig  如果没有安装homebrew 的话 恭喜你 安装去吧.

2. install XQuartz [下载地址](https://xquartz.macosforge.org)

3. brew install Cairo

4. coyped all /opt/X11/lib/pkgconfig/*.pc to /usr/local/lib/pkgconfig on your mac

5. sudo npm install -g qrcode

以上的安装步骤 我可是折腾了足足一个晚上.

写个demo 进行测试下 qrcode.js

var http = require("http");
var QRCode = require('qrcode');
function onRequest(request, response) {
  console.log("Request received.");
  response.writeHead(200, {"Content-Type": "text/html"});
  QRCode.toDataURL("胡峰",function(err,url){
    if(err) console.log('error: '+err);
    //console.log(url);
    response.end("<!DOCTYPE html/><html><head><title>二维码</title></head><body><p >请扫描二维码</p><img src='"+url+"'/></body></html>");
  });
}

http.createServer(onRequest).listen(8888);

node qrcode.js 打开浏览器 ok了


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值