Node.js Flashcards

1
Q

What is Node.js?

A

Program that allows JavaScript to 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 apps
  • Command-line programs
  • 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

o Read-eval-print loop
o Interactive programming environment that takes single user inputs and executes them to return the result to the user (executed piecewise)

For example, the browser console

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

Back-end languages:

A
JavaScript
Java
Python
PHP
Ruby
Go
C++
C# (runs in .NET which is a framework)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a computer process?

A

Instance of a program running in a computer

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

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

A

Because full stack web applications require multiple processes to work together concurrently for it to be useable (multiple processes have to be up and running to properly deal with the app’s clients, servers and databases)

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

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

A

Global object that provides information about/control over the current Node.js process

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

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

A

process

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

What is a JavaScript module?

A

A single .js file

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

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

A
o	exports
o	require 
o	module 
o	\_\_filename
o	\_\_dirname
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A
o	console
o	process
o	Object
o	Undefined
o	global
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

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

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

A

require(‘./filename’)

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

What is the JavaScript Event Loop?

A

How asynchronous callbacks are put back into the call stack when the call stack is clear

17
Q

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

A

o Blocking = Stack is occupied and prevents other code from running (like for-loops)
o Non-blocking = Stack is clear and event loop can occur

18
Q

What is a directory?

A

o Path to where the file is located

o Specific type of file that lists other files

19
Q

What is a relative file path?

A

A path to a file starting from the current directory

20
Q

What is an absolute file path?

A

A path to a file starting from the root (for windows, from the drive name)

21
Q

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

A

fs (file system)

22
Q

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

A

writeFile( )

23
Q

Are file operations using the fs module synchronous or asynchronous?

A

Both

24
Q

What is npm?

A

Makes it easier for javascript developers to share the code they have created to solve particular problems

o stands for node package manager
o Made of 3 parts: Website, CLI and registry

25
Q

What is a package?

A

File or directory that is described by a package.json file

26
Q

How can you create a package.json with npm?

A

npm init –yes

27
Q

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

A

a package you download to run your program; the package should generally have code to implement in your own code

o A npm package installed using npm install
o npm install

28
Q

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

A

A new directory of the package gets created within the current directory

29
Q

How do you add express to your package dependencies?

A

npm install express

30
Q

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

A

.listen( )

31
Q

How do you mount a middleware with an Express application?

A

.use( )

32
Q

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

A

req

res

33
Q

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

A

application/json

34
Q

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

A

o It’s used to recognize incoming requests as JSON object

o To parse incoming request bodies

35
Q

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

A

o It allows us to express our intent – it’s just a string (does not have any special functions or actions)

o Helps capture the value we want to pass to perform a certain action

Note: There is no intrinsic meaning in an http request method

36
Q

What does express.static() return?

A

Return a middleware function that shows the path to a directory so its contents can become publicly accessible

37
Q

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

A

Absolute path to a directory containing the current module

38
Q

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

A

Joins strings together to create a path to a directory