Node.js Flashcards

1
Q

What is Node.js?

A

A program that allows JavaScript to run outside of a web 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

For creating the backend for web applications, writing command line programs, or some kind of automation.

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

What is a REPL?

A

Read-Eval-Print Loop (REPL) is an environment that takes single user inputs, executes them, and returns the results.

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

JS, PHP, Ruby Python Lua
C#, F#, Visual Basic
Java, Kotlin, Clojure Groovy

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

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

A

It provides information about the current Node.js process.

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

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

A

Calling the log method of the console object with one argument, the ‘process’ variable.

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

What is a JavaScript module?

A

A single .js file.

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

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

A

__dirname, __filename, exports, module, require.

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

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

A

process and console.

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

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

A

To allow it’s information to be accessed by other Node.js modules.

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

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

A

The require() function with a (string) parameter of the relative path of another Node.js module.

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

What is the JavaScript Event Loop?

A

It waits for tasks and executes them. If there are no tasks, then it “sleeps” until it receives another task.

It looks at the stack and task queue. If the stack is empty, it takes the first thing on the task queue and puts it on the stack (and runs it).

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

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

A

“Blocking” is executing code that prevents other code from executing until it is finished (“slow” or synchronous).

“Non-Blocking” is code that allows other code to execute while it is preparing itself to execute (“fast” or asynchronous).

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

What is a directory?

A

A structure of folders that also reference other folders.

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

What is a relative file path?

A

Shows how to get from the current working directory to the target file.

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

What is an absolute file path?

A

Shows how to get from the root directory to the target file.

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

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

A

The File System or ‘fs’ module.

20
Q

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

A

The .writeFile() method.

21
Q

Are file operations using the fs module synchronous or asynchronous?

A

fs. …Sync methods are synchronous.

fs.readFile() and fs.writeFile() are asynchronous.

22
Q

What is a client?

A

A computer that accesses a service(s) provided by a server.

23
Q

What is a server?

A

A computer provides a service(s) to one or more clients.

24
Q

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

A

The GET method.

25
Q

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

A

The HTTP method (i.e., GET, PUT, POST, etc.) followed by a resource URL.

26
Q

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

A

The protocol version (i.e., HTTP/1.1) followed by the status code and status code meaning.

27
Q

What are HTTP headers?

A

They allow the client and the server pass additional information with an HTTP request or response.

28
Q

Is a body required for a valid HTTP message?

A

No because not all responses have one.

29
Q

What is NPM?

A

(Node Package Manager) Allows a developers to share code that other developers can reuse in their own applications. NPM consists of the website, software registry, and CLI.

30
Q

What is a package?

A

A directory (sometimes called modules) with one or more files in it including a file called package.json. The file contains meta data about the package.

31
Q

How can you create a package.json with npm?

A

Using the ‘npm init (–yes)’ command.

32
Q

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

A

Other packages that are needed for a package to work. They can be added by using the ‘npm install’ command.

33
Q

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

A

Downloads the dependency to the local directory and updates the package.json file to include the dependency.

34
Q

How do you add express to your package dependencies?

A

The ‘npm install express’ command.

35
Q

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

A

The .listen() method.

“Listening”: Waiting for a request.

36
Q

How do you mount a middleware the an Express application?

A

The .use() method with a parameter of a callback function with parameters, req and res.

When the server receives a request, what do you want to do?

37
Q

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

A

The req (HTTP request message - data model) object, res (HTTP response message - control) object, and the next object.

38
Q

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

A

‘application/json’

39
Q

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

A

Allows the developer to decide what to do in response. It also determines the type of response is sent back to the client.

Semantics only. Expresses the intent of the client.

40
Q

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

A

It parses incoming JSON requests and stores it in req.body as an object.

Only need it when expecting clients to send the server JSON bodies.

41
Q

What is Webpack?

A

Webpack bundles JavaScript modules into a single output file that can be used in the frontend.

42
Q

How do you add a devDependency to a package?

A

npm install –save-dev (name of package)

43
Q

What is an NPM script?

A

NPM scripts are used to automate tasks.

A Command Line command with a nickname (property).

44
Q

How do you execute Webpack with npm run?

A

npm run


45
Q

What does express.static() return?

A

A function.

46
Q

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

A

It stores the value of the directory name of the current module as a string.

47
Q

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

A

It combines the arguments into a single string separated by a forward slash.