SERVER SIDE BACKEND Flashcards
What is the purpose of module.exports in a Node.js module?
It creates a module that can be imported into another file
How do you import functionality into a Node.js module from another Node.js module?
const, var , or let followed by a variable name then assign it a require(directory/filename)
SYNTAX: const add = require(./add) THE .js can be ommitted as it is implied.
What is the JavaScript Event Loop?
It pushes code that is in the callback Queue onto the call stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking is code that must finish before anything else can be done and non-blocking are code that is run immediately onto the stack; Javascript can make blocking into non-blocking by putting it to the side
Directory
a folder that holds file
relative file path
it is within the computer starting from current directory, relative to where you are from
absolute file path
it states the whole path from the root to where it is in the folder
What module does Node.js include for manipulating the file system?
it is fs module
can use require(‘fs);
What method is available in the Node.js fs module for writing data to a file?
fs.writefile
Are file operations using the fs module synchronous or asynchronous?
asynchronous unless stated as synch in the method
What is a client? What is a server?
The client is the one that requests information while the server hosts and wait for request to give the information
Which HTTP method does a browser issue to a web server when you visit a URL?
It uses the GET method
What is on the first line of an HTTP request message?
What is on the first line of an HTTP response message?
A start-line describing if request/response is successful or failed
FOR REquESt: a http method (get, put , post) and the request target usually an absolute path
for Responses: Status Line (protocol version, status code, status text_
What are HTTP headers? Is a body required for a valid HTTP message?
Headers: case insentiive string followed by a colon and a value depending on the type of header, General (via), response(vary and accept-ranges), and representation headers(content-type)
Bodies are not neccessary
What is NPM? What is a package?
It is a package manager, that is open sourced where people can send code or technologies and modify or use that code
A package is a building block that solves one problem and solves it well, a reusable code that can be implemented in custom projects
a Package is:
a) a folder containing a program described by a package.json file
b) a gzipped tarball containing (a)
c) a url that resolves to (b)
d) a @ that is published on the registry (see registry) with (c)
e) a @ (see npm dist-tag) that points to (d)
f) a that has a “latest” tag satisfying (e)
g) a that resolves to (a)