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
┌───────────────────────────┐ | |
┌─>│ timers │ # setTimeout, setInterval | |
│ └─────────────┬─────────────┘ | |
│ ┌─────────────┴─────────────┐ | |
│ │ pending callbacks │ | |
│ └─────────────┬─────────────┘ | |
│ ┌─────────────┴─────────────┐ | |
│ │ idle, prepare │ # system | |
│ └─────────────┬─────────────┘ ┌───────────────┐ | |
│ ┌─────────────┴─────────────┐ │ incoming: │ |
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
setTimeout(function first() { | |
console.log(1) | |
}, 1000) | |
console.log(2) | |
setTimeout(function second() { | |
console.log(3) | |
}, 2000) |
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
document.addEventListener('click', () => { | |
console.log('click') | |
}) |
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
const http = require('http') | |
const hostname = '127.0.0.1' | |
const port = 3000 | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200 | |
res.setHeader('Content-Type', 'text/plain') | |
res.end('Hello World\n') | |
}) | |
server.listen(port, hostname, () => { |
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
const fs = require('fs') | |
fs.readFile('./events.js', function callback(err, data) { | |
console.log('file has been read') | |
}) |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"resolveJsonModule": true, | |
/* Basic Options */ | |
// "incremental": true, /* Enable incremental compilation */ | |
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ | |
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | |
// "lib": [], /* Specify library files to be included in the compilation. */ | |
// "allowJs": true, /* Allow javascript files to be compiled. */ | |
// "checkJs": true, /* Report errors in .js files. */ |
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
function getResponseSize(url) { | |
return fetch(url).then(response => { | |
const reader = response.body.getReader() | |
let total = 0 | |
return reader.read().then(function processResult(result) { | |
if (result.done) return total | |
const value = result.value | |
total += value.length | |
console.log('Received chunk', value) | |
return reader.read().then(processResult) |
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
async function getResponseSizeAsync(url) { | |
const response = await fetch(url) | |
const reader = response.body.getReader() | |
let total = 0 | |
while (true) { | |
const result = await reader.read() | |
if (result.done) { | |
return total | |
} |
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
const { IncomingWebhook } = require('@slack/webhook') | |
const url = process.env.SLACK_WEBHOOK_URL | |
const webhook = new IncomingWebhook(url) | |
// Send the notification | |
(async () => { | |
await webhook.send({ | |
text: 'I\'ve got news for you...', | |
}) | |
})() |
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
#!/usr/bin/env node | |
const { description, name, version } = require('./package.json') | |
const options = process.argv.slice(2) | |
const VERSION_MESSAGE = `${name} ${version}` | |
const HELP_MESSAGE = `${VERSION_MESSAGE} | |
${description} | |
Usage: | |
--help Help documentation |