Node.js & Express.js Flashcards

1
Q

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

A

Fs.writeFile()

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

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

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

What is a directory?

A

A folder that houses grouped files.

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

What is a relative file path?

A

A file location inside of the current directory. A fil relative to the current folder.

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

What is an absolute file path?

A

The full file path or URL, in this instance it’s the full path from the system’s root.
Do not hard code – it’ll break on another computer. Avoid using hard coded absolute file paths.

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

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

A

Fs module.

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

What is npm?

A

npm is the world’s largest software registry that allows JavaScript developers to share code they created to solve specific problems and allows other developers to use that code. It also makes it easy to keep that code up to date. It consists of 3 components, the npm website, the cli, and the registry.

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

What is a package?

A

Packages, or modules, are directories that include a file called package.JSON with meta data about the package, which may contain a program. Usually contains tools needed for a program to work the way we want them to.

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

How can you create a package.json with npm?

A

npm init command – it just creates a file. To create a default package.json, you must navigate to the root of the directory you want to install the package in, then in the terminal, run npm init –yes command.

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

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

A

It is a program or package that a given module requires, or depends upon, to work. To add one, you run the npm install command with the dependency you want to install.

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

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

A

When you run the npm install command, the dependencies get installed to the local node_modules folder, each as a subfolder, and gets added to the package.json file’s dependency object.
By default, npm install will install all modules listed as dependencies in package.json.

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

How do you add express to your package dependencies?

A

npm install express command (after npm init command).

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

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

A

The .listen() method:

const express = require('express');
const app = express();
app.listen(3000, () => {
  // eslint-disable-next-line no-console
  console.log('Express server listening on port 3000');
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you mount a middleware with an Express application?

A

With the .use() method of the app object.

app.use([path,] callback [, callback…])

Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.

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

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

A

The request and response objects.

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

What are express middleware functions?

A

Middleware functions are 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.
The next middleware function is commonly denoted by a variable named next

17
Q

WHAT IS EXPRESS??

A

Express is a routing and middleware Node.js web framework that has minimal functionality of its own: An Express application is essentially a series of middleware function calls.

18
Q

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

A

The MIME type is Application/json – indicates that the request body format is JSON.

19
Q

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

A

To indicate the desired action, but the meaning is what the developer dictates, but we have a convention we follow. We have to tell it to do stuff in the code block.

When it comes to an express application, the application “listens” for requests that match the specified route(s) and method(s), and when it detects a match, it calls the specified callback function.