Node.js Flashcards

1
Q

What is Node.js?

A

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

It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

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), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.

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 is the process object in a Node.js program?

A

Is a global variable that provides information about, and control over, the current Node.js process.

The process object is an instance of EventEmitter.

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

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

A

Call it as you would any other object in JS, it’s global

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

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

A

array or strings

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

What does proces.argv do?

A

The process.argv property returns an array containing the command line arguments passed when the Node.js process was launched.

$ node process-args.js one two=three four

0: /usr/local/bin/node
1: /Users/mjr/work/node/process-args.js
2: one
3: two=three
4: four

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

What is a JavaScript module?

A

each separate js file

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

(function(exports, require, module, __filename, __dirname) {
// Module code actually lives in here
});

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

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

A

console
process

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

Makes things available to other modules in your node. js program

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

call the require function, pass in a relative path, and assign its return value to a variable

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

What is the JavaScript Event Loop?

A

The event loop looks at the stack and the task queue. I the stack is empty, it pushed it from the task queue to the stack, which effectively runs it.

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

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

A

blocking code is occupying the call stack.

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

What is a directory?

A

A file that lists other files and directories.

17
Q

What is a relative file path?

A

a path to a file from where you are currently

18
Q

What is an absolute file path?

A

starts from the root of the file system (starts with a slash)

19
Q

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

A

fs

20
Q

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

A

fs.writeFile

21
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

22
Q

What is NPM?

A

Node packaging manager
npm is the world’s largest software registry. A way for you to reuse code from other developers and for you to share code with them

npm consists of three distinct components:
the website
the Command Line Interface (CLI)
the registry (database of info about packages that people are sharing)

23
Q

What is a package?

A

Bits of reusable code (also sometimes called modules). A package is a directory with one of more files in it that also has a file called package.json with some metadata about this package.

24
Q

How can you create a package.json with npm?

A
  1. On the command line, navigate to the root directory of your package.

cd /path-to-package

  1. Run the following command:

npm init –yes

25
Q

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

A

packages that another package depends on. Packages required by your application in production.

You can add dependencies to a package.json file from the command line or by manually editing the package.json file.
npm install

26
Q

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

A

When you (or another user) run npm install, npm will download dependencies and devDependencies that are listed in package.json that meet the semantic version requirements listed for each

installs the dependencies into the node_modules folder

updates package json to list that package dependency

27
Q

How do you add express to your package dependencies?

A

npm install express

28
Q

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

A

the listen method

29
Q

How do you mount a middleware with an Express application?

A

the use method

30
Q

What are controlled components?

A

The value is kept in a component state.
Listen for when that value changes and update that state

31
Q

What two props must you pass to an input for it to be “controlled”?

A

value prop to tell the input what it’s current value is
onChange

31
Q

What two props must you pass to an input for it to be “controlled”?

A

value prop to tell the input what it’s current value is
onChange

32
Q

What does express.static() return?

A

a function
static files

33
Q

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

A

The directory name of the current module.
it’s an absolute path

34
Q

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

A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.