Skip to content

Instantly share code, notes, and snippets.

@lauras12
Forked from rtanubra/MoreQuestions.txt
Created November 24, 2020 16:10
Show Gist options
  • Save lauras12/13cceea2af7fd89daaf2988731b03576 to your computer and use it in GitHub Desktop.
Save lauras12/13cceea2af7fd89daaf2988731b03576 to your computer and use it in GitHub Desktop.
Node Practice Interview
https://gist.github.com/theperfectfuel/b4ea999d8d827b45edd8de67c46616a3
Moby Dick Coffee
Technologies:
HTML, CSS, JavaScript/ jQuery skills, Node.Js ,Git
Do:
-Update front end responsive designs, bug fixes.
-Create front end apps to integrate to back end applications built in Node.Js
-Create, test, and validata cross browser compatability: templates, pages, sites, mobile devices and older applications;
-Develop templates and interfaces based on UX design prototypes
Needs:
-Responsive design
-Working with Node.JS
-Source control Git
-Consuming REST APIs
-Data interchange like XML and JSON
-Front end debugging tools
https://courses.thinkful.com/mi-fundamentals-v1/checkpoint/1
--Referring to the fundemental section
RESTful APIs
Representational State Transfer. Software architecture style
Set of constraints that governs a specific set of web APIs
The information and decisions you would write in a good api documentation.
Main concerns of Rest:
1. Addresses for endpoints
2. methods do endpoints support
3. what do query strings do
3.1 Should id be in query string or be in body
4. What should be in body and what is in response.
5. How can we ensure performance of the server
6. Manage complexity of the server architecture
Rest Goals:
1. Simple API design and predictable
2. API design consistent
3. Clear direction for API developers and consumers
4. Use HTTP how it was originally intended
5. Clear endpoints naming convention and HTTP method useage
5.1 Delete and Post as they are intended.
5.2 think about query strings
6. Clear patterns in what is contained in responses.
7. flexibility in different implementations. Exact wording of endpoints and how to identify entities
8. Efficient APIS
9. Scalable to support large number of components and interactions.
Constraints of Rest:
1. Seperate concerns client - server architecture. Server data storage and client is interaction.
2. Statelessness. No storing information on server between requests. Everything is contained in the request as they are neeed.
no sessions.
3. Cacheability
3.1 Response are repeatable.
3.2 Some requests can then be cached client side for performance.
4. Layered System.
4.1 Client should not be able to tell if connected to server or intermediary.
5. Uniform interface
1. Describe the HTTP Request Response lifecycle
1.1 https://courses.thinkful.com/async-web-apps-v2/checkpoint/2
1.2 Lets define Internet
1.2.1 Internet: hardware that faciliattes transfer of data between smaller networks
1.2.2 web System of interlinked documents with rules and identifiers on how to retreive them from internet
1.2.2.1 HTML How we structure documents in the web. Affects how people will view them
1.2.2.2 URI's Identify distinct resources on the web.
1.2.2.3 HTTP Rules how servers and browsers communicate to each other.
1.2.3 Client application that requests information from a server
1.3.1 Browser Parses the URL
Breaks up the URL into different parts looks for the domain (main like thinkful.com)
1.3.2 Browser sends the domain name to ISP
1.3.3 ISP looks up domain name in the DNS to find the IP adress
Domain Name System, would be the filing cabinet that has IP adress attached to each domain.
1.3.4 ISP sends IP adress back to the browser
1.3.5 Browser opens up connection to the server at the end of the IP adress
1.3.6 Browser sends request to the server
1.3.7 Server sends a response
1.3.8 6 and 7 will repeat Ie. first HTML then request JS and CSS
2. Describe the architecture of a basic Express App. How is it organized?
2.1 2 Config contains your development variables.
2.2.1 Server module sets up the port and uses development variables to initiate the application
2.2.2 Application. Imported by the server to set as the root of your application. Will import routes.
2.2.3 Data model structures. SRC will be structured similar to data models. Have a folder for each model.
2.2.3.1 Services for each model - contains all the functions to communicate to your database imported by route
2.2.3.2 Routes for each model - imported by root app module. Contains all the endpoint functions relating to this data model.
2.2.4 Explanation- this architecture utilizes Express router to modularize code and seperate the different concerns relating to each data model .
3. Tell me about a time you've used express router and how is it useful.
3.1 Created a full stack budgetting application
3.2 Express was the main framework used to develop the backend of this web application
3.3 This framework created the server that the client application communicated with.
Express created the API that i used to communiate with my client side application
3.3.1 express.Router to modularize my code to the different components
3.3.2 express.json to handle the inputs from my client side application
3.3.3 knex to communicate with database. Therefore, express was middle application between client and database
4. What is the difference between a Unit and intergration testing.
https://courses.thinkful.com/node-postgres-v1/checkpoint/5
4.1 Unit Testing = testing individual components
4.1.1 React Unit testing: Component behaves as expected under all reasonable circumstances.
4.1.2 Functions. Test a specific function ie. divide function. See that the divide function behaves as expected under all normal conditions.
4.2 Integration testing how components behave with other components
4.2.1 testing HTTP protocol client sends request with certain conditions. to a endpoint function on express server.
4.2.2 interface shared boundary across which components exchange data.
4.2.3.1 Client sends HTTP request meeting specific conditions.
4.2.3.2 Express application has specific endpoint function to handle the conditions of the response.
4.2.3.3 Response should meet some specific expectations.
4.3 Systems testing how application behaves along with the people using it and the hardware
4.4 Testing available
4.4.1 Mocha - testing framework (Looks for a test directory. within test you create modules that test parts of your application )
4.4.1.1 Test specific functions
4.4.1.2 Test specific endpoints
4.4.1.3 describe, it, context
4.4.2 Chai an assertion library (expect)
4.4.3 Supertest is a tool for testing HTTP calls.
5. What is SQL and how does it relate to PostgreSQL
5.1 Standard Query Language.
5.1.1 Language used to communicate with database.
5.1.2 Standard language for communicating with relational database.
5.1.3 How we put information, read, and amend our databse.
5.1.4 language that dictates how you interact with data. stored in a database.
5.2 Database is an organized stack of information.
5.3 PostgreSQL
5.3.1 relational database management system built and extended from SQL.
5.3.2 Utilizies SQL language to allow applications or user to interface with data stored in system.
6. What is an XSS attack and do you know any steps to take to prevent them?
https://courses.thinkful.com/node-postgres-v1/checkpoint/16
6.1 Cross-site Scripting
6.2 Maliscious scripts injected into benign websites.
6.2.1 Embedded piece of javascript inside the content of an API response.
6.3 attacker uses web application to send malicious code to a server. In the form of a browser side script. (POST)
6.3.1 hacker posts malicious code into your database.
6.3.2 bad code now sits in database
6.3.3 Another user gets information from your database.
6.3.4 the code is activated stole user 2's information and sends it to hacker.
6.4 Sanitize data is how you prevent this. Prevents in two locations. Sanitize incoming data and sanitize data you send to your users.
6.4.1 to sanitize is to escape any potential JS elements or suspicious JS in response data.
6.4.2 Reads through a string
6.4.3 Removes anything that can be used for an attack
6.4.4 npm install xss
6.4.5 const xss = require('xss')
6.4.6 const sanitizedTitle = xss(title)
6.5 Example attack
6.5.1 Insert an HTML tag that doesn't exist.
6.5.2 Image doesn't work uses the onerror attribute to insert javascript into user b's browser
6.5.3 Would input a fetch to send something to user a about user b's information
7. Practice 1 create and require node module in an express app
7.1 module.exports = {blah,blah1,blah2}
7.1.1 This is used when you declare multiple variables in your application. You can elect what you would like to export by name.
7.1.2 Your export will be a single object. Then you can use object destructuring in the import file.
7.2 const inputFile = require('../somepath/deeper/inputFile')
7.2.1 You can use electively inputFile.myfx(here)
7.2.2 You can declare by name object destructure {myfx, morefx} = inputFile
8. Move a set of endpoints into a router and reconnect the application
https://courses.thinkful.com/node-postgres-v1/checkpoint/11
Bash commands
createuser interview
createdb interviewDb
psql -U interview interviewDb
connect to a db with credentials interview
psql basic client to communicate to your database
\conninfo
-get connection info
\du
-list of database roles
\q
-get out
8.1 make sure that all paths are correct and complete.
8.2 when creating routers make sure we copy paste all exports we need
9. Complete this set of SQL drills
9.1 psql -U dunder_mifflin_admin -d restaurants-app -f ~/Downloads/nyc-restaurants-data-backup.sql
9.2 \dt+ // \d <TABLENAME>
9.3 Specific query questions
9.3.1 Select all restaurants and return all fields
SELECT * FROM restaurants;
9.3.2 Get all restaurants Italian restaurants
SELECT * FROM restaurants WHERE cuisine = 'Italian';
9.3.3 Get 10 Italian restaurants, subset of fields
SELECT id,name FROM restaurants WHERE cuisine='Italian' LIMIT 10;
9.3.4 Count of Thai restaurants ->285
SELECT COUNT(*) FROM restaurants WHERE cuisine='Thai';
9.3.5 Count of restaurants
SELECT COUNT(name) FROM restaurants;
9.3.6 Count of Thai restaurants in zip code
(Just to validate)
SELECT id,name,cuisine, address_zipcode FROM restaurants WHERE cuisine='Thai'AND address_zipcode = '11372';
(obtain answer)
SELECT COUNT(*) FROM restaurants WHERE cuisine='Thai'AND address_zipcode = '11372';
9.3.7 Italian restaurants in one of several zip codes
Write a query that returns the id and name of five Italian restaurants in the 10012, 10013, or 10014 zip codes. The initial results (before limiting to five) should be alphabetically sorted.
SELECT name,id FROM restaurants WHERE cuisine = 'Italian' AND address_zipcode IN('10012','10013','10014') ORDER BY name LIMIT 5;
SELECT id,name,cuisine,address_zipcode FROM restaurants WHERE cuisine = 'Italian' AND address_zipcode IN('10012','10013','10014') ORDER BY name LIMIT 5;
9.3.8 Create a restaurant
INSERT INTO restaurants (name,borough, cuisine, address_building_number, address_street, address_zipcode) VALUES ('Byte Cafe','Brooklyn','coffee','123','Atlantic Avenue','11231');
9.3.9 Create a restaurant and return id and name
INSERT INTO Restaurants (name) VALUES ('Rey') RETURNING (name,id);
9.3.10 Create three restaurants and return id and name
INSERT INTO restaurants (name,cuisine) VALUES ('Erick','Indonesian'), ('Edith','Indonesian'),('Rocky','Indonesian');
9.3.11 Update a record
Update the record whose value for nyc_restaurant_id is '30191841'. Change the name from 'Dj Reynolds Pub And Restaurant' to 'My Restaurant'.
pre-check
SELECT id,name,nyc_restaurant_id FROM restaurants WHERE nyc_restaurant_id='30191841';
UPDATE restaurants SET name = 'My Restaurant' WHERE nyc_restaurant_id = '30191841';
post-check
SELECT id,name,nyc_restaurant_id FROM restaurants WHERE nyc_restaurant_id='30191841';
9.3.12 Delete by id
DELETE FROM grades WHERE id=10;
9.3.13 A blocked delete
Try deleting the restaurant with id of 22. What error do you get?
DELETE FROM restaurants WHERE id = 22;
DETAIL: Key (id)=(22) is still referenced from table "grades".
9.3.14 Create a table
CREATE TYPE bors AS ENUM ('Bronx', 'Brooklyn', 'Manhattan', 'Queens', 'Staten Island');
CREATE TABLE inspectors (
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
first_name text NOT NULL,
last_name text NOT NULL,
borough bors
);
9.3.15 Update a table
ALTER TABLE grades
ADD notes text;
ALTER TABLE grades
ALTER COLUMN notes INTEGER;
9.3.16 Drop a Table
DROP TABLE inspectors;
9.3.17 Join stuff
Get the name, cuisine, grade, score
SELECT r.name, r.cuisine, g.grade ,g.score
FROM restaurants r
INNER JOIN grades g
ON r.id = g.restaurant_id
ORDER BY score DESC
LIMIT 10 ;
SELECT r.name, r.cuisine, r.borough, g.score, g.grade
FROM restaurants r
INNER JOIN grades g
ON r.id = g.restaurant_id
ORDER BY score DESC
LIMIT 10;
SELECT e.name AS "exp_name", e.expense, u.user_name AS "usr_name"
FROM trafus_expenses e
INNER JOIN trafus_users u
ON e.creator_id = u.id;
SELECT e.name AS "exp_name", e.expense, c.name AS "cat_name", c.budget
,e.expense/c.budget * 100 AS "perc_budget"
FROM trafus_expenses e
INNER JOIN trafus_categories c
ON e.category_id = c.id
ORDER BY c.name;
SELECT e.name AS "exp_name", e.expense, c.name AS "cat_name", c.budget
,e.expense/c.budget * 100 AS "perc_budget"
FROM trafus_expenses e
INNER JOIN trafus_categories c
ON e.category_id = c.id
WHERE c.id=4;
SELECT u.id AS "usr_id", u.user_name AS "usr_name"
,t.name AS "tme_name", t.id AS "tme_id"
FROM trafus_users u
INNER JOIN trafus_teams t
ON u.team_id = t.id
ORDER BY t.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment