npm Flashcards

1
Q

What is NPM?

A

Node package manager - a way to reuse/use code from other developers and also to share your code, which makes it easy to manage the different versions of code

  1. website
  2. the Command Line Interface (CLI)
  3. the registry
  4. Use the website to discover packages, set up profiles, and manage other aspects of your npm experience. For example, you can set up organizations to manage access to public or private packages.
  5. The CLI runs from a terminal, and is how most developers interact with npm.
  6. The registry is a large public database of JavaScript software and the meta-information surrounding it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a package?

A

a directory with one or more files and it contains the file package.json

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
  1. go to the root directory of the package.

2. 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

Packages required by your application in production.

You can add to a package by “npm install (package-name)”

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

the dependency key will be listed in the package’s package.json file

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

listen( ) method

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

the use( ) method

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
request object (req)
 response object (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 is the significance of an HTTP request’s method?

A

It determines the different actions that can be done depending on the method.

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

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

A

It parses incoming requests with JSON payloads and returns the object containing parsed data on req.body.
You would need it when your app needs to parse JSON request bodies.

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

What is Webpack?

A

webpack bundles your JS application by automatically building your dependency graph based on what is imported and exported

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

How do you add a devDependency to a package?

A

–save-dev

example:
npm install –save-dev

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

What is an NPM script?

A

it is a property of package.json and can be executed by running npm run; CLI command you can run

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

How do you execute Webpack with npm run?

A

npm run build — where build is the property of scripts with the value “webpack”

can change word build but will have to change in the command line too.

17
Q

What does express.static() return?

A

returns middleware function

18
Q

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

A

The directory name of the current module.

19
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.

20
Q

Serving static files in Express

A

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express.