Misc Flashcards
Triggering a download when clicking a link
a:href=:download=:target=
href points to the file to download;
download triggers download in some cases, and defines the name of the, it declares the download intent;
target attribute when pointing to _blank, causes the file to be downloaded when paired with download attribute, otherwise it causes the file to open in another tab/window.
Using download + target covers most download trigger scenarios
Yarn vs Npm main differences
Yarn is faster (parallel installation);
Yarn can cache packages to install projects faster;
Yarn locks down dependecies versions by default, making installing the same project in multiple places more stable;
Yarn doesnt work with any older version of npm (5?).
adding, deleting modules in Yarn vs Npm, updating dependencies
npm install x yarn add x npm/yarn remove x yarn upgrade npm update
HTTP vs HTTPS
HTTP = hyper text transfer protocol S = secure, makes your connection encrypted
Why is it important to set inputs names in forms?
Not only to handle them with JS, but to send a properly named body buffer to the server ex: message=something
How and why access the vscode debug tools
Pressing F5, allows you to place breakpoints, see variable contents in real time, and track variables along the execution of a program.
Its also possible to write code while on a breakpoint in the debug mode
Debug doesnt offer you a terminal that is not the debug terminal, and you have to manually go to the starting point everytime you want to debug, how to fix that?
Creating a launch.json file in a .vscode folder: debug>add configuration, adding the ‘console’ option and setting the preferred console, and changing the “program” property to the entrypoint of your application.
Can you change variables in your code on the fly with vscode debugger?
Yes
Option to set the default runtime tool when debugging your code with vscode inside launch.json
“runtimeExecutable”: “[node | nodemon]”
What is MVC
MVC stands for model, view, controller
consider this code: const products = {...};
class product{ constructor(t){ this.title = t; } static const findCheapest(){ var cheapest = products[0]; for (item in products){ if (item.price < cheapest.price) cheapest = item.price; } return cheapest; } }
Router.get('/findProducts', (req, res) => { const cheapest = product.findCheapest(); res.render('/product', {product: cheapest}); });
How would you separate it between a model, a controller, and a route file?
model:
const products = {…};
class product{ constructor(t){ this.title = t; } static const findCheapest(){ var cheapest = products[0]; for (item in products){ if (item.price < cheapest.price) cheapest = item; } return cheapest; } }
route:
Router.get(‘/findProducts’, controllerFunction);
controller:
req, res) => { const cheapest = product.findCheapest(); res.render('/product', {product: cheapest}); }
what is the main reason to use string to represent keys and values in json?
main reason according to json creator douglas crockford, is to avoid reserved words in multiple languages.