LFZ Quiz questions (Senior parts) Flashcards
What is a JavaScript module?
In the Node.js module system, each file is treated as a separate module. Single JS file.
What is a JavaScript module?
Single JS file. In the Node.js module system, each file is treated as a separate module.
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, and __dirname
Give two examples of truly global variables in a Node.js program.
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()
What is the purpose of module.exports in a Node.js module?
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 do you import functionality into a Node.js module from another Node.js module?
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.
What are serialization and deserialization and why are they useful?
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.
What is a server?
What is a client?
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
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What is the format of an HTTP request message?
- 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)
What is the format of an HTTP response message?
- 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 do you add express to your package dependencies?
npm install express
What Express application method binds the server to a network PORT?
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 do you register a middleware with an Express application?
We can use use method.
ex) app.use
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request and response objects