web development concepts Flashcards

1
Q

What are the examples of HTTP Methods???

A

The different Verb for HTTP Protocol. Examples are GET, POST, PUT DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does res.json do?

A

The res.json() function sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using the JSON.stringify() method.
Syntax:

res.json( [body] )
Parameters: The body parameter is the body which is to be sent in the response.
Return Value: It returns an Object.
Installation of express module:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Difference of res.json, res.send

A

res.JSON() is identical to res.send() when an object or array is passed, but it also converts non-objects to json.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

HTTP response status code?What are the five types?

A
Informational responses (100–199)
Successful responses (200–299)
Redirection messages (300–399)
Client error responses (400–499)
Server error responses (500–599)

read this for more

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is HTTP Body Data?

A

HTTP Body Data is the data bytes transmitted in an HTTP transaction message immediately following the headers if there is any (in the case of HTTP/0.9 no headers are transmitted).

Most HTTP requests are GET requests without bodies. However, simulating requests with bodies is important to properly stress the proxy code and to test various hooks working with such requests. Most HTTP requests with bodies use POST or PUT request method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the definition of protocol according to MDN

A

Protocol

A protocol is a system of rules that define how data is exchanged within or between computers.

Communications between devices require that the devices agree on the format of the data that is being exchanged. The set of rules that defines a format is called a protocol.

In non-programming context, it means below

the system of rules and acceptable behaviour used at official ceremonies and occasions
禮儀,禮節
a breach of Royal protocol
對皇家禮儀的違反
diplomatic protocol
外交禮儀
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the definition of HTTP

A

HTTP is a protocol for fetching resources such as HTML documents. It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser. A complete document is reconstructed from the different sub-documents fetched, for instance, text, layout description, images, videos, scripts, and more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the definition of interface?

A

Interfaces help developers to specify the behaviours of a type without actually specifying the internal implementations. Here is one example of an interface:

interface FlyingAnimal {
fly( height: number):void;
}
Let’s say you have an interface called FlyingAnimal which is used to describe any animals that fly. It has a method called fly(height:number) to specify how high this animal should fly upon calling. It is a common practice to specify only the methods but not the properties to make the interface as flexible as possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the use of JSON.stringify()

A

The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

(See examples on MDN if forget)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does “new” do in Javascript do? Examples?

A

New keyword in JavaScript is used to create an instance of an object that has a constructor function. On calling the constructor function with ‘new’ operator, the following actions are taken:

A new empty object is created.
The new object’s internal ‘Prototype’ property (__proto__) is set the same as the prototype of the constructing function.
The ‘this’ variable is made to point to the newly created object. It binds the property which is declared with ‘this’ keyword to the new object.
A newly created object is returned when the constructor function returns a non-primitive value (custom JavaScript object). If the constructor function returns a primitive value, it will be ignored. At the end of the function, ‘this’ is returned if there is no return statement in the function body.

function Fruit(color, taste, seeds) {
    this.color = color;
    this.taste = taste;
    this.seeds = seeds;
}
// Create an object
const fruit1 = new Fruit('Yellow', 'Sweet', 1);
// Display the result
document.write(fruit1.color);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does JSON.parse do?

A

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does parse mean in computer science?

A

In computer science, parsing is the process of analysing text to determine if it belongs to a specific language or not (i.e. is syntactically valid for that language’s grammar). It is an informal name for the syntactic analysis process.

For example, suppose the language a^n b^n (which means same number of characters A followed by the same number of characters B). A parser for that language would accept AABB input and reject the AAAB input. That is what a parser does.

In addition, during this process a data structure could be created for further processing. In my previous example, it could, for instance, to store the AA and BB in two separate stacks.

Anything that happens after it, like giving meaning to AA or BB, or transform it in something else, is not parsing. Giving meaning to parts of an input sequence of tokens is called semantic analysis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

in reading JSON, require(“.file.json) VS fs.readFile,

what is the difference?

A

require(“./file.json) caches result, which mean it will be store in the program who call it and won’t change even when the retrieved json file is changed. (it will autoly parse the json. Downside, this is sync, it will block other code until it is loaded. But it is good at configuation because you want other data to run after that. Also, it loads faster because it is cache.

fs.readFile, read current state of file, must parse data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

is readFileSync sync or async?

A

it is async!! Check it out in VScode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

if a function returns a value, and you add a console.log , will it display in the console

A

NO, if you console.log the function, it will only display the returned value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

using fs.readFile, what is the data type when you have JSON file as parameter?

A

it is STRING

17
Q

What do fetch() return?

A

promise, use VScode to check to know, need to add await then async function to process.

18
Q

What is the difference of Body.json and JSON.parse()

A

36

Body.json() is asynchronous and returns a Promise object that resolves to a JavaScript object. JSON.parse() is synchronous can parse a string and change the resulting returned JavaScript object.

The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON.

Note that despite the method being named json(), the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.

19
Q

When you see Promise {}, what mistake you are likely to make?

A

You set it to be a sync function, and you should be using async function, like await

20
Q

for many response.method, such as response.text, response.json or res.text and res.json, what is the type of their return value

A

mostly promise, according to Dickson

21
Q

Whati is CORS

A

Cross-Origin Resource Sharing (CORS)
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a “preflight” request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.

An example of a cross-origin request: the front-end JavaScript code served from https://domain-a.com uses XMLHttpRequest to make a request for https://domain-b.com/data.json.

For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. For example, XMLHttpRequest and the Fetch API follow the same-origin policy. This means that a web application using those APIs can only request resources from the same origin the application was loaded from unless the response from other origins includes the right CORS headers.

22
Q

What is the use of URL.createObjectURL(result)

A

it create a temporary link! It will disappear if the website is refreshed.

23
Q

What is blob?

A

A binary large object (BLOB) is a collection of binary data stored as a single entity. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob. … The term is also used by languages that allow runtime manipulation of Blobs, like JavaScript.

24
Q

What is Connection pool

A

In software engineering, a connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools are used to enhance the performance of executing commands on a database. Opening and maintaining a database connection for each user, especially requests made to a dynamic database-driven website application, is costly and wastes resources. I

25
Q

如果出現error的話, 那為什麼要.end 來中斷是服務器跟客戶端的連接???

用什麼手段來做成這件事?

A

如果不中斷的話會卡死在那個error裡面.
運作不了, 而且connect也會中斷不了, 浪費ram

try, catch, finally

26
Q

Is socket.io a http?

A

No