Node Flashcards

(45 cards)

1
Q

What is Node.js?

A

a JavaScript runtime that is asynchronous and event driven.

Environment that lets us execute JavaScript code that doesn’t use a browser

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

What can Node.js be used for?

A

It can be used to write command line tools and server-side scripting, making JavaScript to be the language for both server and client side

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

What is a REPL?

A

Read-Eval-Print-Loop. Takes user-made input and returns it one line at a time

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

When was Node.js created?

A

May 27, 2009

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

What back end languages have heard of?`

A

Python, JavaScript, Java, Ruby, C#, C++, PHP

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

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

A

Its a global that provides info about and control over the current Node.js process

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

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

A

Use the process variable

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

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

A

Returns an array

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

What is a JavaScript module?

A

It is a single ‘.js’ file meant to separate out some functionality

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

What values are passed into a Node.js module’s local scope?

A

‘module,’ ‘require,’ ‘exports,’ ‘__dirname,’ ‘__filename’

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

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

A
  • global
  • console
  • setTimeout()
  • clearInterval()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

Allows data types to be returned from a module called by using ‘require()’

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

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

A

the require() function.

The source module contains the desired functionality within its code, followed by exports.name = name

The calling module contains the name, using a require()

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

What is a directory?

A

A file that lists locations to other files

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

What is a relative file path?

A

Set of directions from the current directory to its destination

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

What is an absolute file path?

A

A path to a file that has the entire path shown, from its root element to its final destination

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

Are file operations using the ‘‘fs’ module synchronous or asynchronous?

20
Q

What is a client?

A

A requester of services from a server

21
Q

What is a server?

A

A provider of services to one or many clients (does the processing)

22
Q

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

23
Q

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

A
  • The type of request (GET, POST, PUT), known as an HTTP method
  • The URL
  • The HTTP version
24
Q

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

A
  • The protocol
  • The status code (200, 404, etc)
  • The human readable status (Success, file not found, etc.)
25
What are HTTP headers?
A space for clients/servers to pass additional information about a request to each other, known as meta info
26
Is a body required for a valid HTTP message?
No, it is not required
27
What is NPM?
Nope Package Manager
28
What is a package?
a file or directory
29
How can you create a 'package.json' with 'npm'?
Use the CLI command `npm init --yes`
30
What is a dependency and how do you add one to a package?
- A dependency is a package from an external source that is used in your program, making your program dependent on it - The `npm install (package name)` command automatically adds the dependency to the `package.json` file. Otherwise, include it in the `package.json` file.
31
What happens when you add a dependency to a package with 'npm'?
It automatically adds the dependency into the `package.json` file
32
How do you add 'express' to your package dependencies?
npm install express
33
What Express application method starts the server and binds it to a network PORT?
listen() method
34
How do you mount a middleware with an Express application?
the Use method of the App object
35
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
- `req` - the request object - `res` - the response object - `next()` - the next middleware function in the application's request-response cycle
36
What is the appropriate `Content-Type` header for HTTP messages that contain JSON in their bodies?
`application/json`
37
What is the significance of an HTTP request's method?
It signifies the intent of the request, and can help a server developer design how a request should be handled
38
What does the 'express.json()' middleware do and when would you need it?
Allows for parsing of JSON requests on requests made to an endpoint (route) You need it when you are expecting to receive JSON requests and want to work with the JSON data as a JavaScript object
39
What is Webpack?
A module bundler, compiling many files into one file
40
How do you add a 'devDependency' to a package?
npm install --save-dev
41
What is an NPM script?
They are scripts made available in the `package.json` file that allow you to run commands from NPM
42
How do you execute Webpack with 'npm run'?
Add a `build` to the NPM `package.json`'s `scripts` section, with the command being just `webpack`
43
What does 'express.static()' return?
A function `serveStatic`
44
What is the local '_dirname' variable in a Node.js module?
The absolute path directory name of the module
45
What does the 'join()' method of Node's 'path' module do?
Joins strings together into a coherent path