Node.js Flashcards

1
Q

What is Node.js?

A

An asynchronous event-driven JavaScript runtime, Node.js is a program that allows JavaScript to be run outside of a web 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

Build back ends for Web applications, command-line programs, or any kind of automation

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

What is a REPL?

A

A Read-Eval-Print-Loop (REPL) reads input from the user, executes them, and returns the result to the user.

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

When was Node.js created?

A

2009

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

What back end languages have you heard of?

A

PHP, Ruby on Rails, C#, Java

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

What is a computer process?

A

The execution of code/program/application by one or more threads

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

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

hundreds

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

Why should a full stack Web developer know that computer processes exist?

A

Full stack is made up of many modules. To track the status of the server, check its pid.

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

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

A

Global variable with information about and control over the current Node.js process.

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

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

A

process variable

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

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

A

Array of strings

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

What is a JavaScript module?

A

JavaScript file

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

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

A

dirname, filename, exports, required

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

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

A

process, argv, console

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

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

A

Allows you to write modular code and easily reuse it by importing and exporting.

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

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

A

Use require.

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

What is a directory?

A

A node in the file system that contains other files and directories.

18
Q

What is a relative file path?

A

A path with . or .. to indicate current dir and parent dir respectively.

19
Q

What is an absolute file path?

A

A path with the all parent dirs from the root down.

20
Q

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

A

fs

21
Q

How do you add express to your package dependencies?

A

npm install

22
Q

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

A

listen

23
Q

How do you mount a middleware with an Express application?

A

Use a middleware method: use(), get(), post(), put(), delete()

24
Q

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

A

req, res, and next

25
Q

What is NPM?

A

the website, command line interface, and registry

26
Q

What is a package?

A

Module that has been added to npm’s registry

27
Q

How can you create a package.json with npm?

A

npm init

28
Q

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

A

A package the module uses or needs. npm install

29
Q

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

A

Adds dependency to node module dir. Adds it to package.json.

30
Q

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

A

application/json; charset=utf-8

31
Q

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

A

Parses http request body from JSON to an object. Needed when you expect a JSON string in a http post request

32
Q

What is Webpack?

A

Webpack bundles together JS modules into one file to prevent a network bottleneck that could occur when loading multiple files. Webpack uses Immediately invoked function expressions (IIFE) to concatenate files without scope collision.

33
Q

How do you add a devDependency to a package?

A

Install dependency and check that it shows up in package.json under dependencies.

34
Q

What is an NPM script?

A

NPM supports a number of built-in scripts. To use, list them in your package.json under scripts and call NPM build on them.

35
Q

How do you execute Webpack with npm run?

A

Insert a “build” property under scripts in package.json. Run “npm run build”.

36
Q

What does express.static() return?

A

Middleware function that serves static files

37
Q

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

A

Path of the current JavaScript file’s directory.

38
Q

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

A

Concatenates the two args, which should represent paths and directory names

39
Q

What does fetch() return?

A

a promise

40
Q

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

A

GET

41
Q

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

A

{ method: }