Promise.resolve().then vs setImmediate vs nextTick

Using Promise.resolve().then has no advantages over nextTick. It runs on the same queue, but have slightly higher priority, that is, promise handler can prevent next tick callback from ever running, the opposite is not possible. This behaviour is an implementation detail and should not be relied on. Promise.resolve().then is obviously slower (a lot, I think), … Read more

Socket.io custom client ID

You can create an array on the server, and store custom objects on it. For example, you could store the id created by Socket.io and a custom ID sent by each client to the server: var util = require(“util”), io = require(‘/socket.io’).listen(8080), fs = require(‘fs’), os = require(‘os’), url = require(‘url’); var clients =[]; io.sockets.on(‘connection’, … Read more

adding .css file to ejs

Your problem is not actually specific to ejs. 2 things to note here style.css is an external css file. So you dont need style tags inside that file. It should only contain the css. In your express app, you have to mention the public directory from which you are serving the static files. Like css/js/image … Read more

How to access Google Chrome’s IndexedDB/LevelDB files?

Keys in leveldb are arbitrary binary sequences. Clients implement comparators to define ordering between keys. The default comparator for leveldb is something equivalent to strncmp. Chrome’s comparator for Indexed DB’s store is more complicated. If you try and use a leveldb instance with a different comparator than it was created with you’ll observe keys in … Read more

Go to the TypeScript source file instead of the type definition file in VS Code

Since Typescript 2.9 it is possible to compile your library with the declarationMap flag ./node_modules/typescript/bin/tsc -p . –declarationMap Doing so creates a declaration map file (dist/ActionApi.d.ts.map) and a link to the map at the bottom of the corresponding d.ts file //# sourceMappingURL=ActionApi.d.ts.map When VSCodes encounters such a declarationMap it knows where to go to and … Read more

Puppeteer wait for all images to load then take screenshot

There is a built-in option for that: await page.goto(‘https://www.digg.com/’, {“waitUntil” : “networkidle0”}); networkidle0 – consider navigation to be finished when there are no more than 0 network connections for at least 500 ms networkidle2 – consider navigation to be finished when there are no more than 2 network connections for at least 500 ms. Of … Read more