Created
July 30, 2020 02:08
-
-
Save awssimplified/af89d729ae3f19bdcb7b326738820205 to your computer and use it in GitHub Desktop.
Revisions
-
awssimplified created this gist
Jul 30, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ NodeJS --- Every file is a 'module' console.log(`Hi ${this.name}!`); <-- `` Templating Make sure to use the relative path when importing or node will think you are using the built in module exports.sayHello = function() { console.log("Hello!"); }; ^ is same as: module.exports = { name: "Elie", sayHello() { console.log("Hello!"); } }; Default module functions: module.exports = function() { console.log("I am the entire module!"); }; allows you to do --> evenMoreHelpers() Destructuring Objects --- Allows for quick shorthand extraction of fields from objects. Example below const obj = { first: 'Jane', last: 'Doe' }; const {first: f, last: l} = obj; //f = 'Jane'; l = 'Doe' // {prop} is short for {prop: prop} const {first, last} = obj; // first = 'Jane'; last = 'Doe' Destructuring Arrays --- const iterable = ['a', 'b']; const [x, y] = iterable; // x = 'a'; y = 'b' Event Loop --- Stack which holds calls to be processed immediately Async calls get added to the event loop Event loop is a queue Once the stack is cleared, calls from the event loop start getting executed in order of insertion (FIFO) async.js --- shorthand for promise.all() <-- waiting for multiple promises to resolve before executing the callback function Process Module --- Used to invoke CMD arguments environment variables accessed using process.env process.argv gives you command line arguments process.env.ENV_VAR Good read for event loop stuff --- https://blog.risingstack.com/node-hero-async-programming-in-node-js/