SERVER SIDE BACKEND Flashcards

1
Q

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

A

It creates a module that can be imported into another file

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

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

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the JavaScript Event Loop?

A

It pushes code that is in the callback Queue onto the call stack

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

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

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

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

Directory

A

a folder that holds file

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

relative file path

A

it is within the computer starting from current directory, relative to where you are from

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

absolute file path

A

it states the whole path from the root to where it is in the folder

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

What module does Node.js include for manipulating the file system?

A

it is fs module

can use require(‘fs);

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

What method is available in the Node.js fs module for writing data to a file?

A

fs.writefile

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

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous unless stated as synch in the method

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

What is a client? What is a server?

A

The client is the one that requests information while the server hosts and wait for request to give the information

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

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

A

It uses the GET method

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

What is on the first line of an HTTP request message?

What is on the first line of an HTTP response message?

A

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_

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

What are HTTP headers? Is a body required for a valid HTTP message?

A

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

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

What is NPM? What is a package?

A

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)

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

How can you create a package.json with npm?

A

navigate to the root path and then run : npm init

17
Q

What is a dependency and how to you add one to a package?

A

Packages that it depends on whether it is a package lock, shirnkwrap file or yarn lock, the installation of dependencies will be driven by that npm install

18
Q

What happens when you add a dependency to a package with npm?

A

It creates a folder in the node modules directory and add to the dependencies

19
Q

How do you add express to your package dependencies?

A

npm install express

require(‘express’)

20
Q

what Express application method starts the server and binds it to a network PORT?

A
listen method
const app =express();
app.listen(3000, () =. {
(code here)
});
21
Q

How do you mount a middleware with an Express application?

A

app.use() the first parameter is the path where the middleware function executes when the base of the req path matches path

22
Q

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

A

(req, res) request and response; (request object is passed in)

23
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json which runs UTF encoding

24
Q

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

A

The significance is that it will determine what the response will be, it by letting the server know what to do do

25
Q

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

A

It is so that the app will be able to read and parse incoming requests with JSON loads Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option

26
Q

What does express.static() return?

A

(it returns a function that

does HTTP 404 Not Found if the file is not there otherwise it returns your file.

27
Q

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

A

The directory name of the current module, it is the same path as (path.dirname(__filename));

28
Q

What does the join() method of Node’s path module do?

A

Joins all given path segments together

EXample SetUP:
const joinedPath = path.join(\_\_dirname, 'public');
app.use(express.static(joinedPath));