node-promisify

How to use await with promisify for crypto.randomBytes?

匆匆过客 提交于 2021-02-11 17:01:06
问题 I'm writing a function to generate a random key using crypto.randomBytes, which takes a callback. I'd prefer to use async await so I'm trying to use util.promisify to wraprandom bytes like this: const crypto = require('crypto'); const util = require('util'); const randBytes = util.promisify(crypto.randomBytes); async function genRandKey() { bytes = await randBytes(48).catch((err) => { console.log(err); }); return bytes.toString('hex'); } let result = genRandKey(); console.log('key: ', result)

TypeError [ERR_INVALID_ARG_TYPE]: The “original” argument must be of type function puppeteer node js

末鹿安然 提交于 2020-07-10 03:24:05
问题 I am stuck here for a while I didn't understand the problem. Kindly someone enlightens me on this topic. here's the code. const puppeteer = require('puppeteer'); (async() => { let infourl = 'https://www.imdb.com/title/tt0111161/?ref_=fn_al_tt_3'; let browser = await puppeteer.launch(); let page = await browser.newPage(); await page.goto(infourl, { waitUntil:'networkidle2' }); let data = await page.evaluate( () =>{ let stats = document.querySelector('div[class="title_wrapper"]').innerText;

Redis won't retrieve data from cache

こ雲淡風輕ζ 提交于 2020-03-21 12:05:28
问题 I'm following a tutorial and I created a cache.js file that takes the mongoose query and JSON.stringifies it into the key for the values being returned by that query. The goal is to cache that and then append .cache() inside app.js where the mongoose.find() is Currenty if the cache is empty, I have it do a GET from the DB and then store it in the cache. I have a console.log("CACHE VALUE #2"); console.log(cacheValue1); that ensures that the data is getting stored and outputs the data