-
-
Save garenyondem/09455cd37bc3c33b916f6a675e552924 to your computer and use it in GitHub Desktop.
Generate QR Code and save to mongodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const qr = require('qr-image'); | |
const mongoose = require('mongoose'); | |
const Grid = require('gridfs'); | |
const json = { | |
email: '[email protected]', | |
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