Skip to content

Instantly share code, notes, and snippets.

@dalaidunc
dalaidunc / read.js
Last active January 5, 2019 11:44
2 approaches to reading text files with node.js
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const readdir = util.promisify(fs.readdir);
async function read1 (file) {
const label = `read1-${file}`;
console.time(label);
const data = await readFile(file, 'utf8');
@dalaidunc
dalaidunc / async-await-simple.js
Created July 7, 2017 23:48
Async / Await simple example
/* === EXAMPLE 1 === */
// Create a simple Promise wrapper for setTimeout
function wait (ms) {
return new Promise (resolve => setTimeout(resolve, ms));
}
// Declare an async function
async function hello (name) {
// wait for the specified time