// Node.js | |
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
rl.on('line', (input) => { | |
if (input === 'ping') { |
html, body, div, form, fieldset, legend, label { margin: 0; padding: 0; } | |
table { border-collapse: collapse; border-spacing: 0; } | |
th, td { text-align: left; vertical-align: top; } | |
h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; } | |
img { border: 0; } |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft
,elem.offsetTop
,elem.offsetWidth
,elem.offsetHeight
,elem.offsetParent
When first confronted with node.js, you are not only presented with a completely new programming environment. You also encounter what is often referred to as callback hell accompanied by weird unfamiliar programming patterns. One of these is the way node treats callback functions.
The following post explains the conventions that node.js uses for its callback patterns (referred to as Continuation-passing style) and how you should implement them in order to comply.
Node expects - almost - all callback functions to accept an Error object as the first argument. If no error occurred, the first argument should be null. If you use inline anonymous functions, this is a typical code snippet that you will encounter using node:
// include the filesystem module
var fs = require('fs');
// Node.js | |
const sum = (a, b) => { | |
return Number(a) + Number(b); | |
}; | |
process.stdin.on('data', (data) => { | |
const [a, b] = data.toString().split(' '); | |
const result = sum(a, b); | |
process.stdout.write(result.toString()); | |
process.exit(0); |
// Node.js | |
const fs = require('fs'); | |
const sum = (a, b) => { | |
return Number(a) + Number(b); | |
}; | |
const fileContent = fs.readFileSync("input.txt", "utf8"); | |
const [a, b] = fileContent.toString().split(' '); | |
const result = sum(a, b); |