Node/Express Flashcards

1
Q

What does express.static() return?

A

It returns static files such as images, CSS files, and JavaScript files. It’s built-in middleware.

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

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

A

Path to directory

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

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

A

Join the paths that are provided in arguments.
express.static(path.join(__dirname, ‘public’))

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

What does fetch() return?

A

It returns a promise.

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

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

A

Get method

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

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

A

As an argument of fetch method

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

What is Node.js?

A

Program that allows JavaScript to be run outside of the browser or program written in C++ and embedded in JavaScript engine.

Definition - Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser
Outside of the browser - not interacting with Web UI (HTML, CSS) It’s backend programming interacting with databases.

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

What can Node.js be used for?

A

Backend applications and command-line programs.

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

What is a REPL?

A

take data from input and return something.
The Node.js Read-Eval-Print-Loop (REPL) is an interactive shell that processes Node.js expressions. The shell reads JavaScript code entered by users, evaluates the result of interpreting the line of code, prints the result to the user, and loops until the user signals to quit.

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

When was Node.js created?

A

2009 Ryan Dehl(was building a website and notice it didn’t scale)

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

What back end languages have you heard of?

A

Scripting languages : PHP, PYTHON, RUBY, PERL, JS, LUA System languages: C, C++, Rust, Zig. Byte Code languages Java, C#, Kotlin,

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

What is a computer process?

A

Instance of a running program

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

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

A

Global object that can be accessed without requiring it.

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

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

A

Process object is a global object and can be accessed inside any module without requiring it using keyword “process”.

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

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

A

The data type of process.argv in Node.js is an array of strings.

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

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

A

process, url, console.log,

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

What is a JavaScript module?

A

It’s a file with a reusable code which we can use in different file.

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

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

A

Purpose of module.exports is to have access to code in different file.

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

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

A

Using require function

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

What is a directory?

A

Directory lists other directories or files. It points to a location

21
Q

What is a relative file path?

A

Relative path points to file which is relative to our current position.

22
Q

What is an absolute file path?

A

An absolute path tells all details about directories starting from the root.

23
Q

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

A

fs (file system module)

24
Q

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

A

writeFile()

25
Q

Are file operations using the fs module synchronous or asynchronous?

A

both

26
Q

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

A

Blocking means when execution of additional processes must wait. Non-blocking when execution of additional processes don’t have to wait.

27
Q

What is a client?

A

Something(program or person) requests service from a server

28
Q

What is a server?

A

Resources provider

29
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET method

30
Q

What is on the first line of an HTTP request message?

A

HTTP Method, URL(target), protocol version

31
Q

What is on the first line of an HTTP response messages?

A

Protocol Version, Status Code, Status text

32
Q

What are HTTP headers?

A

Part of HTTP request/response object, contains vital information about http request/response. (string, key-value pairs)

33
Q

What is NPM?

A

node package manager for node JavaScript platform.

34
Q

What is a package?

A

The package is a file or directory that contains code described by package.json ( package has to have package.json)

35
Q

How can you create a package.json with npm?

A

Using command npm init

36
Q

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

A

Dependencies are packages needed to run your app. You need to install them using npm install

37
Q

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

A

It will add key-value pair to jason file and let us use code/programs provided by package code

38
Q

How do you add express to your package dependencies?

A

npm i express

39
Q

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

A

app.listen()

40
Q

How do you mount a middleware with an Express application?

A

By using use method. (app.use) optionally adding path and req,res

41
Q

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

A

req,res object

42
Q

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

A

application/json

43
Q

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

A

The method tell the parties involved what kind of activity is occurring…its more semantics

44
Q

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

A

It parses incoming payload. We need it when receiving data from client(user)

45
Q

What three things are on the start-line of an HTTP response message?

A

Protocol version (HTTP/1.1) Status Code, Status text

46
Q

What are endpoints?

A

Endpoints are communication channels (to get data) describes in routes. Most endpoints work through http or https

47
Q

What is routing?

A

Routing refers to how application’s endpoints (URLs) respond to client requests .

48
Q

What is event loop?

A

Event Loop is a mechanism which JavaScript uses to manage executing functions asynchronously. It’s build in libuv library.