LFZ Quiz questions (Senior parts) Flashcards

1
Q

What is a JavaScript module?

A
In the Node.js module system, each file is treated as a separate module.
Single JS file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a JavaScript module?

A
Single JS file.
In the Node.js module system, each file is treated as a separate module.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What values are passed into a Node.js module’s local scope?

A

exports, require, module, __filename, and __dirname

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

Give two examples of truly global variables in a Node.js program.

A

https://nodejs.org/docs/latest-v10.x/api/globals.html

Global Objects

Class: Buffer
\_\_dirname
\_\_filename
clearImmediate(immediateObject)
clearInterval(intervalObject)
clearTimeout(timeoutObject)
console
exports
global
module
process
require()
setImmediate(callback[, ...args])
setInterval(callback, delay[, ...args])
setTimeout(callback, delay[, ...args])
URL
URLSearchParams
WebAssembly
==> module scope: It appears global
\_\_dirname
\_\_filename
exports
module
require()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of module.exports in a Node.js module?

A

Module exports are the instruction that tells Node.js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code.

To understand modules in Node.js, I like to imagine all my modules written together in one file (not as modules), and then imagine what code I’d need to make that happen. The code would look like each module wrapped in a function and given an argument, which is the current module.

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

How do you import functionality into a Node.js module from another Node.js module?

A

Require is a function we can use to import other modules.

Require will search for modules using the following rules:

Is there a core module with the required path? Yes, return it.
Is there a node_modules package with the name of the path? Yes, return it.
Is there a file (or directory!) with the name of the given path? Yes, return it.
Otherwise, throw an error.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are serialization and deserialization and why are they useful?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

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

What is a server?

What is a client?

A

Client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients.
Servers are classified by the services they provide. For example, a web server serves web pages and a file server serves computer files

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

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

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

What is the format of an HTTP request message?

A
  • Start line: HTTP method, request target, HTTP version
  • Headers: General headers, Response headers, Entity headers
  • Body: Single-resource bodies(Content-Type and Content-Length), Multiple-resource bodies(HTML Forms)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the format of an HTTP response message?

A
  • Status line: protocol version, status code, status text
  • Headers: General headers, Response headers, Entity headers
  • Body: responses with a status code that sufficiently answers the request without the need for corresponding payload
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you add express to your package dependencies?

A

npm install express

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

What Express application method binds the server to a network PORT?

A

app.listen([port[, host[, backlog]]][, callback])
Binds and listens for connections on the specified host and port. This method is identical to Node’s http.Server.listen().

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

How do you register a middleware with an Express application?

A

We can use use method.

ex) app.use

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

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

request and response objects

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

(express-sendfile)

What is the Content-Type header of HTTP requests and responses used for?

A

Content-Type response HTTP header field based on the filename’s extension.
ex)
Content-Type: application/javascript; charset=UTF-8
Content-Type: text/css; charset=UTF-8
Content-Type: text/html; charset=UTF-8

17
Q

(express-static)

What does express.static() return?

A

Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.

18
Q

(express-static)

What is the local __dirname variable in a Node.js module?

A

The directory name of the current module

19
Q
(express-static)
What does the join() method of Node's path module do?
A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

20
Q

(express-get-json)

What is the appropriate Content-Type header for requests and responses that contain JSON in their bodies?

A

Content-Type: application/json; charset=utf-8

21
Q

(express-post-json)

What does the express.json() middleware do and when would you need it?

A

It parses incoming requests with JSON payloads and is based on body-parser.
If servers need to handle JSON file type, express.json() middleware must be called before using it.

22
Q

(express-delete)

What is the significance of an HTTP request’s method?

A

A route path and request URL can be determined by requesting methods.

23
Q

(webpack-intro)

What is Webpack?

A

t’s a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS), and it can be extended to support many different assets such as images, fonts and stylesheets. Webpack applies the concept of modules to any file in your project.

24
Q

(webpack-intro)

How do you add a devDependency to a package?

A

npm install –save-dev
or
npm install -D

25
Q

(webpack-intro)

What is an NPM script?

A

npm run build

npm command line

26
Q

(webpack-intro)

How do you execute Webpack with npm run?

A

“scripts”: {
“build”: “webpack”,
}

ex)
"scripts": {
    "dev": "webpack --mode=development --watch --devtool=source-map",
    "build": "webpack --mode=preduction"
}
27
Q
(es-modules)
What is an ES6 module and how is it different from a CommonJS module?
A

ES6 module can support browsers whereas CommonJS supports only server sides. ES6 module supports AMD(Asynchronous Module Definition)