Node.js Flashcards

1
Q

What is Node.js?

A

a JavaScript runtime build on Chrome’s V8 JavaScript engine

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

its used for backend and command line scripts

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

What is a REPL?

A

Read, Evaluate, Print, Loop

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

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

A

The process object is 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
5
Q

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

A

reference it

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

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

A

Array of strings

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

What is a JavaScript module?

A

a file that contains related code

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

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

A

exports, require, filename, dirname

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

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

A

process, global

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

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

A

To export a piece of code so other files are able to access it

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

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

A

you add module.exports to whatever code you want to export and then require method to where you want to use it

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

What is the JavaScript Event Loop?

A

a runtime model that is responsible for executing code, collecting and processing events and executing queued sub-tasks.

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

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

A

Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn’t block execution.

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

What is a directory?

A

A special file that lists other files and directories

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

What is a relative file path?

A

relative file path tells you how to get to a file from your current location

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

What is an absolute file path?

A

location of a file from the root directory

17
Q

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

A

fs

18
Q

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

A

writeFile

19
Q

What is NPM?

A

npm is a registry that contains code packages

20
Q

What is a package?

A

a file or directory that is described by a package.json file

21
Q

How can you create a package.json with npm?

A

npm init

22
Q

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

A

a dependency is something that your package depends on and to add one use npm install

23
Q

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

A

it updates your package json and downloads the package from the npm registry

24
Q

How do you add express to your package dependencies?

A

npm install express –save

25
Q

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

A

listen

26
Q

How do you mount a middleware with an Express application?

A

use method

27
Q

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

A

request and response

28
Q

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

A

appication/json

29
Q

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

A

This method is used to parse the incoming requests with JSON body and is based upon the bodyparser. You would need it when you want to receive JSON data and add it to a data model

30
Q

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

A

it defines the action to be performed

31
Q

What does express.static() return?

A

it returns a path

32
Q

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

A

The directory name of the current module

33
Q

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

A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.