Skip to content

Instantly share code, notes, and snippets.

@garenyondem
Forked from sjcotto/qrCode.js
Last active October 10, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garenyondem/09455cd37bc3c33b916f6a675e552924 to your computer and use it in GitHub Desktop.
Save garenyondem/09455cd37bc3c33b916f6a675e552924 to your computer and use it in GitHub Desktop.
Generate QR Code and save to mongodb
'use strict';
const qr = require('qr-image');
const mongoose = require('mongoose');
const Grid = require('gridfs');
const json = {
email: 'john@doe.com',
name: 'John Doe'
};
let image = qr.imageSync(JSON.stringify(json), { type: 'png', size: 10 });
let gfs = Grid(mongoose.connection.db, mongoose.mongo);
let fileId = new mongoose.mongo.ObjectId();
gfs.writeFile({ _id: fileId, content_type: 'image/png' }, image, function (err, file) {
console.log(file);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment