Title: Theory / Important / CS / Programming / JS / Node
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Language: js
Language: js

Name: Node.js
Definition: open-source and cross-platform JavaScript runtime environment.
Page: https://nodejs.dev/learn/

Question: Main difference between server and client side js
Answer: In server, you control which version of node you use
Page: https://nodejs.dev/learn/differences-between-nodejs-and-the-browser
Answer2: Different library. window on client, filesystem on server

Name: V8
Definition: Chromium
Page: https://nodejs.dev/learn/differences-between-nodejs-and-the-browser
Definition2: Node.js
Conjdef: Used by
Definition3: Edge recently
DefType: Javascript engine.

Name: SpiderMonkey
Definition: Firefox javascript engine
Page: https://nodejs.dev/learn/differences-between-nodejs-and-the-browser

Name: JavaScriptCore
Definition: Safari javascript engine
Page: https://nodejs.dev/learn/differences-between-nodejs-and-the-browser

Name: Chakra
Definition: javascript engine previously in Edge
Page: https://nodejs.dev/learn/differences-between-nodejs-and-the-browser

Instruction: node foo
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: Run the node.js application from file foo

Variable: process.exitCode
Meaning: The exit code that will be provided when the program halt, if no explicit code is passed
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Initialization: 0

Instruction: process.exit(n)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: Immediately halt the node server and exit with code n
Context: node

Instruction: process.exit()
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: Immediately halt the node server and exit with code process.exitCode (default 0)
Context: node

Instruction: node
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: run node.js in repl mode

Instruction: .help
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: shows the dot commands help
Context: node repl

Instruction: .editor
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: enables editor mode, to write multiline JavaScript code with ease. Once you are in this mode, enter ctrl-D to run the code you wrote.
Context: node repl

Instruction: .break
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: will abort further input.
Context: node repl
Abbreviation: pressing ctrl-C.
Where to use it: inputting a multi-line expression

Instruction: .clear
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: resets the REPL context to an empty object and clears any multi-line expression currently being input.
Context: node repl

Instruction: .load
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: loads a JavaScript file, relative to the current working directory
Context: node repl

Instruction: .save
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: saves all you entered in the REPL session to a file (specify the filename)
Context: node repl

Instruction: .exit
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: exits the repl
Context: node repl
Abbreviation: pressing ctrl-C two times

Instruction: console.log(
  foo_1,
  ...,
  foo_n
)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: print foo_1, ... and foo_n on standard output
Context: node

Instruction: console.log(
  'foo',
  param_1,
  ...,
  param_n
)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: print foo on standard output, replacing the i-th argument %s/%d... by param_i
Context: node

Instruction: console.trace()
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: Print the entire stacktrace on stdout
Context: node

Instruction: console.time(foo)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: Start a timer associated to name foo
Context: node

Instruction: console.timeEnd(foo)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: print on stdout the time since stopwatch foo was started with console.time(foo)
Context: node

Instruction: chalk.color(foo)
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: node
Returns: string foo plus an instruction to print it in color

Instruction: require('foo')
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: node
Returns: module named or in file foo

Variable: module.exports
Meaning: the value obtained when the current file is imported
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: node

Name: node package manager
Definition: manages downloads of dependencies of your project.
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: js
Abbreviation: npm

Fla: install
Effect: install everything required by package.json
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm

Fla: install foo
Effect: install package foo
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm

Fla: --save
Effect: adds the entry to the package.json file dependencies
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm install foo

Fla: --save-dev
Effect: installs and adds the entry to the package.json file devDependencies
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm install foo

Variable: dependencies
Meaning: dependencies that are used in prod
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: node.js dependencies

Variable: devDependencies
Meaning: dependencies that are used in development.
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: node.js dependencies
Example: testing libraries

Fla: update
Effect: check all packages for a newer version that satisfies your versioning constraints.
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm

Fla: update foo
Effect: update package foo satisfying package.json constraint
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm

Variable: scripts
Meaning: dictionnary from command to way to run them
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm
Typ: package.json

Fla: run foo
Effect: execute the command indicated in package.json's `script[foo]`
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm

Fla: -g
Effect: install globaly on your system
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Context: npm install

Instruction: npx foo
Page: https://nodejs.dev/learn/run-nodejs-scripts-from-the-command-line
Effect: find, install and execute foo, without using npmt
Context: npm

Variable: package.json
Meaning: kind of a manifest for your project.
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm

Variable: name
Meaning: the name of the package
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: version
Meaning: the version of the package
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: Description
Meaning: a brief description of the app/package
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: private
Meaning: whether the app/package to be accidentally published on npm
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: main
Meaning: the entry point for the application
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: engines
Meaning: sets which versions of Node.js this package/app works on
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: browserlists
Meaning: used to tell which browsers (and their versions) you want to support
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: author
Meaning: information on the author of this package
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: contributors
Meaning: information on the contributors to this package
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: bugs
Meaning: link to bug tracker
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: homepage
Meaning: the package homepage
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: licence
Meaning: the license of the package.
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: keywords
Meaning: array of kewyord for searching in packages
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json

Variable: repository
Meaning: where the package repository is located
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm package.json
Example: "github:whatever/testing"

Instruction: ~major.minor.patch
Page: insthttps://nodejs.dev/learn/the-package-json-guide
Effect: Accept versions major.minor and any patch
Context: npm package-lock.json version

Instruction: ^major.minor.patch
Page: insthttps://nodejs.dev/learn/the-package-json-guide
Effect: Accept versions major, any minor and any patch
Context: npm package-lock.json version

Instruction: major.minor.patch
Page: insthttps://nodejs.dev/learn/the-package-json-guide
Effect: Accept only version major.minor.patch
Context: npm package-lock.json version

Variable: package-lock.json
Meaning: the acceptable version of each dependencies
Page: insthttps://nodejs.dev/learn/the-package-json-guide
Context: npm

Fla: list
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm
Print: the version of all installed npm packages, including their dependencies:

Fla: -g
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm list
Print: show package globally installed instead

Fla: package_name
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm list
Print: limit to dependencies of package_name

Fla: version
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm list package_name
Print: the version number of the installed version of package_name

Fla: --depth=i
Effect: limit packages dependencies to depth i
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm list

Instruction: < foo, <= foo, > foo, >= foo
Page: https://nodejs.dev/learn/the-package-json-guide
Effect: Any version less/greater than (or equal to) foo
Context: npm version

Instruction: foo - bar
Page: https://nodejs.dev/learn/the-package-json-guide
Effect: Any version between foo and bar
Context: npm version

Instruction: foo || bar
Page: https://nodejs.dev/learn/the-package-json-guide
Effect: Any version satisfying either foo or bar
Context: npm version

Fla: uninstall foo
Effect: uninstall package foo
Page: https://nodejs.dev/learn/the-package-json-guide
Context: npm

Fla: --save
Effect: also remove it from package.json
Page: https://nodejs.dev/learn/the-package-json-guide
Flag abbreviation: -S
Context: npm uninstall foo

Fla: --global
Effect: also uninstall globally
Page: https://nodejs.dev/learn/the-package-json-guide
Flag abbreviation: -g
Context: npm uninstall foo

Name: The event loop
Definition: The process of using a message queue to execute things one after the other, and enqueue things to allow for asynchronous process
Page: https://nodejs.dev/learn/the-nodejs-event-loop

Name: The message queue
Definition: A queue of every function calls that are ready to be executed
Page: https://nodejs.dev/learn/the-nodejs-event-loop

Name: A tick
Definition: The end of a full trip of the event loop
Page: https://nodejs.dev/learn/understanding-process-nexttick

Instruction: process.nextTick(foo)
Page: https://nodejs.dev/learn/understanding-process-nexttick
Effect: Execute foo at the end of this tick
Context: node

Question: Difference between process.nextTick(foo) and `setTimeout(foo, 0)`
Answer: nextTick execute at the end of the tick. `setTimeout(foo, 0)` execute at the end of the next tick
Page: https://nodejs.dev/learn/understanding-process-nexttick
Context: node

Instruction: setImmediate(foo)
Page: https://nodejs.dev/learn/understanding-process-nexttick
Effect: Execute foo as the next iteration of the event loop
Context: node

Question: How to immediately start an expansive method foo
Answer: setImmediate(foo)
Page: https://nodejs.dev/learn/understanding-process-nexttick
Context: node

Name: Error first callback
Definition: A callback whose first argument is an error. It is null if there is no error
Page: https://nodejs.dev/learn/javascript-asynchronous-programming-and-callbacks
Context: node

Name: ommitted
Definition: promise part
Page: https://nodejs.dev/learn/javascript-asynchronous-programming-and-callbacks
Context: node

Instruction: eventEmitter.on(
  'foo',
  bar
)
Page: https://nodejs.dev/learn/the-nodejs-event-emitter
Effect: when foo is emitted with arguments args, call bar(args)
Context: node
Library: events

Instruction: eventEmitter.emit(
  'foo',
  args
)
Page: https://nodejs.dev/learn/the-nodejs-event-emitter
Effect: call the listener for event foo with arguments args
Context: node
Library: events

Instruction: Buffer.from(foo)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: A buffer containing the content of foo
Context: node
Library: buffer

Instruction: Buffer.alloc(n)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: A buffer of size n bytes, initialized with 0
Context: node
Library: buffer

Instruction: Buffer.allocUnsafe(n)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: A buffer of size n bytes, with unknown content
Context: node
Library: buffer

Instruction: buf.subarray(
  min,
  max
)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: A slice of buf from min to max
Context: node
Variables: buf a Buffer
Library: buffer

Instruction: buf.set(foo)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: set the content of buf to foo
Context: node
Variables: buf a Buffer
Library: buffer

Instruction: buf.set(
  foo,
  pos
)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: set the content of buf to foo, starting at pos
Context: node
Variables: buf a Buffer
Library: buffer

Typ: Buffer
Meaning: An array of data of fixed size
Page: https://nodejs.dev/learn/nodejs-buffers
Language: js
Context: node

Typ: Stream
Meaning: Some data that can be processed by batch
Page: https://nodejs.dev/learn/nodejs-buffers
Language: js
Context: node
Intuition: a file, read part by part, a network operation received from start to end

Instruction: stream1.pipe(stream2)
Page: https://nodejs.dev/learn/nodejs-buffers
Effect: pipe stream1 into stream2
Context: node
Returns: stream2
Variables: Stream stream