npm Flashcards

1
Q

What is NPM?

A

software registry where open source developers can share and borrow packages

consists of website, command line interface (CLI), and the registry

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

What is a package?

A

a file or directory that is described by a package.json file that contains reusable code

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

How can you create a package.json with npm?

A

npm init –yes

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

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

A

a dependency is a package that the project depends on

npm install

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

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

A

package gets installed in a folder called node-modules and package.json is updated

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

How do you add express to your package dependencies?

A

npm install express

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

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

A

app.listen(PORT, function)

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

How do you mount a middleware with an Express application?

A

call a middleware method like app.use()

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

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

A

req and res

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

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

A

application/json

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

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

A

it parses incoming requests in json, used when incoming requests have json bodies

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

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

A

determines what action SHOULD be done with the given resource but programmer can make it do whatever
if empty code block, then httpie freezes for 30s

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

What does express.static() return?

A

a middleware function preprogrammed to look in a directory and serve files

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

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

A

string of directory name of the current module (absolute path)

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

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

A

joins path names

path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does fetch() return?

A

returns a promise for a response

17
Q

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

A

get

18
Q

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

A

pass an object containing the method

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#syntax

19
Q

When does React call a component’s componentDidMount method?

A

invoked immediately after a component is mounted (inserted into the tree)

20
Q

Name three React.Component lifecycle methods.

A
componentDidMount
componentDidUpdate
componentWillUnmount
constructor
render
21
Q

How do you pass data to a child component?

A

pass it as an argument props