ES6/Node.js/npm/express Flashcards

1
Q

What is a code block? What are some examples of a code block?

A

A code block is sets of code that are enclosed in {} curly braces. An example would be a function code block.

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

What does block scope mean?

A

Variables that exist only when they are within a block?
What happens in the code block, it stays inside the code block

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

What is the scope of a variable declared with const or let?

A

blocked scope variable

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

What is the difference between let and const?

A

let variables can be reassigned while const variables cannot

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

Why is it possible to .push() a new value into a const variable that points to an Array?

A

Because we are not reassigning the array itself, we are adding new variables into the array

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

How should you decide on which type of declaration to use?

A

You should use let when you know you are going to reassign the variable. And typically use const when you know you are not going to change it.

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

What is the syntax for writing a template literal?

A

${variable_name}

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

What is “string interpolation”?

A

It is a feature that has the ability to sub parts of a string with values of variables or expressions

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

What is destructuring, conceptually?

A

breaking down arrays or objects and giving values and properties a variable

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

What is the syntax for Object destructuring?

A

const or let {object_properties} = object_name;

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

What is the syntax for array destructuring?

A

const or let [variable_names] = object_name;

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

How can you tell the difference between destructuring and creating Object/Array literals?

A

by seeing which side the equal sign shows up

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

What is the syntax for defining an arrow function?

A

let myFunction = (…args) => expression

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

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

nothing, only use curly braces for block syntax

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

How is the value of this determined within an arrow function?

A

it captures the value of the enclosing context instead of creating its own

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

What is a CLI?

A

command line interface

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

What is a GUI?

A

graphic user interface

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

Give at least one use case for each of the commands listed in this exercise.
-man
-cat
-ls
-pwd
-echo
-touch
-mkdir
-mv
-rm
-cp

A

man (manual) - man cat
cat (outputs contents) - cat example.txt
ls (list of files) - ls example/
pwd (presents working directory) - pwd
echo (display line of text) - echo ‘Hello, World!’
touch (change file timestamps and file creation) - touch create-file.txt
mkdir (make directories) - mkdir example
mv (move or rename files) - mv pokimans pokemon
rm (remove files) - rm example.txt
cp (copy files and directories) - cp example.txt example2.txt

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

What are the three virtues of a great programmer?

A

laziness, impatience, hubris

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

What are the 3 components of a fullstack Web architecture?

A

presentation(frontend), logic(backend), data tiers

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

What is Node.js?

A

designed to build scalable network applications as an asynchronous event-driven JavaScript runtime for servers

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

What can Node.js be used for?

A

server side of javascript, to get requests from the server

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

What is a REPL?

A

Read–eval–print loop takes single user inputs, executes them, and returns the result to the user

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

When was Node.js created?

A

May 27, 2009

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

What backend languages have you heard of?

A

Ruby, PHP, Java

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

What is a computer process?

A

an instance of a computer program being executed by one or more threads

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

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

a lot (mine has 420 processes)

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

Why should a full stack Web developer know that computer processes exist?

A

so you know how your application interacts with the operating system (OS) and hardware

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

What is the process object in a Node.js program?

A

provides information about, and control over, the current Node.js process

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

How do you access the process object in a Node.js program?

A

process

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

What is the data type of process.argv in Node.js?

A

an array of strings

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

How do you access the command line arguments in a Node.js program?

A

process.argv[2]

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

What is a JavaScript module?

A

it is a single ‘.js’ file and node is made up of multiple modules

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

What are the advantages of modular programming?

A

since you are breaking a big solution/problems into a lot of smaller ones, it can be an advantage by being able to be more organized with your code as well as help you solve parts at a time

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

In JavaScript, how do you make a function in a module available to other modules?

A

by exporting

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

In JavaScript, how do you use a function from another module?

A

by importing

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

What is the JavaScript Event Loop?

A

a series of code/calls waiting or in queue to be put in the call stack where the code will execute

38
Q

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

A

blocking is code that blocks further execution until the operation is finished while non-blocking is code that doesn’t block further executions

39
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

40
Q

How do you handle the fulfillment of a Promise?

A

by using .then(value)

41
Q

How do you handle the rejection of a Promise?

A

by using .catch(error)

42
Q

What does Array.filter do?

A

it filters out values in an array based on the callback function

43
Q

What should the callback function return?

A

a boolean

44
Q

What is Array.filter useful for?

A

when filtering out specific values and elements in an array

45
Q

What does Array.map do?

A

it creates a new array filled with the new values from the function

46
Q

What should the callback function return?

A

a new array with the result of the function

47
Q

What is Array.map useful for?

A

so that you can keep the original array

48
Q

What does Array.reduce do?

A

process and reduce an array of values to a single value

49
Q

What action should the callback function perform?

A

it should take two parameters, the accumulator and the current value, it goes through each iteration of the accumulator

50
Q

What should the callback function return?

A

it should return accumulated value at each iteration from the callback function

51
Q

What is Array.reduce useful for?

A

its useful when you need to transform an array of values into a single value

52
Q

What is a directory?

A

a folder

53
Q

What is a relative file path?

A

a file that is relative to the current directory that is being worked on

54
Q

What is an absolute file path?

A

a file that is found through the root directory

55
Q

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

A

the fs file system

56
Q

What method is available in the node:fs module for reading data from a file?

A

the fileRead method, you have to import ‘node:fs’, and then call it with (path, option)

57
Q

What method is available in the node:fs module for writing data to a file?

A

the writeFile method, you have to import ‘node:fs’ and then call it (file, data, option, callback)

58
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

59
Q

What is a client?

A

a client is a piece of hardware or software that is used by the server for the client-server-model, it usually sends a request to another program so that it accesses a service made for the server

60
Q

What is a server?

A

it’s a piece of hardware or software that provides the functionality for other programs (clients)

61
Q

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

A

GET method

62
Q

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

A

request method, request target, and version
GET https://example.com HTTP/1.1

63
Q

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

A

protocol version, status code, status text
HTTP/1.1 403 Forbidden

64
Q

What are HTTP headers?

A

it adds additional info/context for the request

65
Q

Is a body required for a valid HTTP message?

A

No

66
Q

What is NPM?

A

node package manager, is open source that allows people to share and borrow packages

67
Q

What is a package?

A

a directory with one or more files that includes the package.json file

68
Q

How can you create a package.json with npm?

A

first navigate to the root directory and then use npm init -yes

69
Q

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

A

it’s a package that is depended on another package, you can add one by using the command npm install <package-name></package-name>

70
Q

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

A

the devDependencies will get stored in the package.json file and it will create a node_module file

71
Q

What are some other popular package managers?

A

npm, Yarn, PNPM, Homebrew

72
Q

What is Express useful for?

A

express is useful for building web applications as it helps Node manage servers and routes

73
Q

How does Express fit into a full-stack web application?

A

it manages the http request (we can think of it as a middle man between frontend and backend

74
Q

How do you add express to your package dependencies?

A

by installing express
npm install express

75
Q

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

A

the listen() method

76
Q

What is Express middleware?

A

functions that are executed between the processing of a request and the sending of a response.

77
Q

What is Express middleware useful for?

A

it executes in between a request and a response (it can be used for authentications, data parsing, logging, and error handling)

78
Q

How do you mount a middleware with an Express application?

A

by using the .use() method

79
Q

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

A

the request and response objects and next function

80
Q

What is an API endpoint?

A

the url

81
Q

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

A

application/json

82
Q

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

A

it allows the client to perform actions on the server (retrieving, creating, updating, and deleting data)

83
Q

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

A

it is a built in function that takes the requests and parses the JSON data into an object and puts it on req.body

84
Q

What is the purpose of the Express Static middleware?

A

to process static files in an express app

85
Q

What does express.static() return?

A

a middleware function that serves static files

86
Q

What are several examples of static files?

A

HTML, CSS, images

87
Q

What is a good way to serve application images using Express?

A
88
Q

How to start express app:

A

cd directory_name -> npm init -> npm install express -> npm install nodemon

89
Q

What does fetch() return?

A

a promise that resolves to the response object

90
Q

What is the default request method used by fetch()?

A

GET

91
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

{method: method_name} as the second argument of the fetch() callback function

92
Q

How does fetch report errors?

A

try and catch