NPM/Express/Babel Flashcards

1
Q

What is NPM?

A

Node package manager, software registry that makes it easy for JS developers to share reusable code to solve problems
- website, command line client, registry

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

What is a package?

A

directory with one or more files inside and package.json file

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 -y (for default) in current directory

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

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

A

Any other packages that your package depends on

**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 package name is added under “dependencies” in package.json
  • npm will downloads listed dependencies under node-modules directory
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

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

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

request and response objects

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

What is the purpose of the Content-Type header in HTTP request and response messages?

A

In a response, the header tells the client what kind of file type the returned content is
In a request, the client tells the server what kind of information is being sent

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

What does express.static() return?

A

a middleware function that returns static files such as images, CSS files, and JavaScript files in the specified root directory

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

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

A

full directory name of current module or absolute path

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

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

A

concatenates individual segments or strings together to form a file path

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

middleware functions (express)

A

functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle

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

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

A

It parses incoming requests from JSON

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.

only need this that is supposed to receive json

17
Q

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

A

Tells the server what the client is trying to do (ex. get information, post information, delete information, etc)

18
Q

What is Webpack?

A

a tool that allows let us take JS modules and bundle them together

**module butler

19
Q

How do you add a devDependency to a package?

A

npm install –save-dev webpack

npm install –save-dev

20
Q

What is an NPM script?

A

Written in package.json as key/value pair, a script to help to automate tasks (command line command) name: key, value: what you want to execute

21
Q

How do you execute Webpack with npm run?

A

List it as a script under package.json “scripts”

22
Q

How are ES Modules different from CommonJS modules?

A

No export.modules or require

**export keyword in front of whatever you want to export, then import _ from “file path”

23
Q

What kind of modules can Webpack support?

A

ES2015 import, CommonJS require, AMD define/require, @import statment css/sass/less, img url in stylesheet url() or HTML img src file

24
Q

What is Babel?

A

JavaScript compiler/toolchain used to convert JS code to older versions to be compatible with older browsers and environments

25
Q

What is a Plug-in?

A

a software component that adds a specific feature to an existing computer program.

26
Q

What is a Webpack loader?

A

transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them

27
Q

How can you make Babel and Webpack work together?

A

in your webpack config object:

  • loader: babel-loader
  • Options property -> plugins: [] array of wanted plugins