Node.js Flashcards

1
Q

What is Node.js?

A

an open-source, asynchronous JavaScript runtime environment built on Chrome’s V8 JavaScript engine, which executes outside the browser

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

What can Node.js be used for?

A

build scalable server side network applications

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

What is a REPL?

A

a read-eval-print loop is a language shell

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

When was Node.js created?

A

2009

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

What back end languages have you heard of?

A

PHP, Python, Ruby, Java, C#

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

What is a CLI?

A

command line interface, a text-based user interface

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

What is a GUI?

A

graphical user interface

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

Give at least one use case for each of the commands listed in this exercise.

A

man -read about a command in the manual
cat -combine text files, print out
ls -list contents of a directory
pwd -view current directory
echo -write a string to a text file, command line
touch -create a new text file, updated access stamp on files
mkdir -create a new directory
mv -move a file to another directory, rename files
rm -remove a file from the hard drive
cp -copy a file

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

What is a computer process?

A

the instance of a computer program that is being executed by one or more threads

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

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

A

~200

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

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

A

a full stack web app is made form multiple processes together

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

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

A

a global that 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
14
Q

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

A

access it directly with ‘process’ in Node.js, since it is a global object

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

What is a JavaScript module?

A

a single JavaScript file

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

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

A

parameters: exports, require, module, __filename, __dirname

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

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

A

clearImmediate(immediateObject)
console
process

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

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

A

to export code to be used in another module

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

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

A

by calling the require() function (with the argument being a string of the path to the JavaScript file) and assigning the return to a variable

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

What is the JavaScript Event Loop?

A

a cycling process for how JavaScript executes code in a non-blocking manner, checks if there is something in the call stack again and again, and if not then checks the callback queue (which is made up of completed web APIs),
-if there is something in the queue, it gets moved to the call stack

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

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

A

blocking code waits for each line of code to be resolved in the call stack, while non-blocking code moves code off to a task queue so that the call stack is not blocked from continuing to run

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

What is a directory?

A

a pointer or container for files

24
Q

What is a relative file path?

A

the location of a file from the current file

25
Q

What is an absolute file path?

A

a complete path, the location of a file from anywhere

starts with a slash /

26
Q

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

A

fs module

27
Q

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

A

the fs.writeFile() method

28
Q

Are file operations using the fs module synchronous or asynchronous?

A

asychronous on fs module, though both are possible in node

29
Q

stdin

A

process input

30
Q

stdout

A

process output for normal output (logs to the terminal), ex. process.stdout.write()

31
Q

stderr

A

process output for errors

32
Q

TCP

A

machines connect to a network, then can connect to each other, sending data back and forth

33
Q

What is a client?

A

a program or computer which is a data requestor or accesses a service, or a web browser

34
Q

What is a server?

A

a program or computer which is a data provider or provides functionality to clients

35
Q

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

A

GET method

36
Q

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

A

HTTP method, request target, HTTP version

37
Q

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

A

protocol version, status code, status text

38
Q

What are HTTP headers?

A

additional information which specifies the request or describe the body included in the message

39
Q

Is a body required for a valid HTTP message?

A

No, it’s optional

40
Q

What is NPM?

A

a JavaScript package manager, CLI, website, software registry

41
Q

What is a package?

A

a file in a directory with a package.json, reusable code which can be shared

42
Q

How can you create a package.json with npm?

A

the CLI command “npm init –yes”

43
Q

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

A
  • a package that your app relies on to function

- npm install

44
Q

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

A

the package and any of its dependencies are installed in the ‘node-modules’ folder, also altering the package.json file

45
Q

How do you add express to your package dependencies?

A

npm install express

46
Q

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

A

app.listen([port[,host[,backlog]]][,callback])

47
Q

What is Express?

A

back end web application framework for Node.js

48
Q

How do you mount a middleware with an Express application?

A

app.use([path,] callback [,callback…]) method

49
Q

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

A

req (request) and res (response) objects

50
Q

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

A

application/json

51
Q

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

A

HTTP request methods mean what we want to do, but can actually do anything

52
Q

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

A
  • parses the JSON request body to a JavaScript object

- when you will receive JSON from the request body

53
Q

npm run dev:server

A
  • nodemon watches js so it auto restarts server
54
Q

Promise

A

an object representing the eventual completion or failure of asynchronous operation

55
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

56
Q

How do you handle the fulfillment of a Promise?

A

.then() method, pass a handler function as an argument

57
Q

How do you handle the rejection of a Promise?

A

.then() or .catch() method, pass a handler function as an argument