Node.js Flashcards

1
Q

What is Node.js?

A

Node.js is an open-source, cross-platform JS runtime environment

Running a javascript code without being in the web broswer

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

Used for server-side programming
primarily deployed for non-blocking, event-driven servers like traditional websites and back-end API services

Build a back-end, make command-line app, automated scripts in JS

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:
- it reads, evaluates, prints the result and then loop it by writting again in the next line

examples: console.logs() & browser dev 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 - 2011

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

ruby, PHP, python, C++, java, C, C#, JS, perl, kotlin

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

control over information that is executing the current node

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

You can just reference it because it is a global object

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

it is an array of strings

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 specific individual 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

__dirname & __filename & exports & module & require()

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

global & process & console object

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

Module.exports are the instructions that tell Node.js which bits of code (functions, objects, strings, etc) to export from a given file so that other files are allowed to access the exported code

To expose values to grab other files

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

const variableName = require(‘fileName’)

Pulling information from another module

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

What is the JavaScript Event Loop?

A

part of the JS runtime environment that pushes asynchronous callbacks onto the call stack when the call stack is clear.

example: ajax, delay time

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

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

A

blocking: operations that block further execution until that op finishes - need to wait for other things to finish - anything that is sitting on the call stack
- For example: for-loop

non-blocking: code that doesn’t block execution - other things will execute while waiting for this code to be executed when there’s like a delay
- HTTP request,

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

What is a directory?

A

a special file that lists files and directories

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

What is a relative file path?

A

the location that is relative to a current directory

18
Q

What is an absolute file path?

A

specifying the location of a file or directory from the root directory - using a ‘/’

takes you to the file from anywhere

19
Q

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

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?

22
Q

What is NPM?

A

It’s a software registry. Open-source developers to share and borrow packages. It consists of these three things: website, cli, and registry.

23
Q

What is a package?

A

directory with one or more files & package.json

24
Q

How can you create a package.json with npm?

A

npm init –yes

25
What is a dependency and how do you add one to a package?
npm install 'packageFile' Dependency: a third-party code that your application depends on. piece of software that your software will need.
26
What happens when you add a dependency to a package with npm?
The package.json is updated with the new dependency and the package is downloaded from NPM registry to node_modules
27
How do you add express to your package dependencies?
npm install express
28
which Express application method starts the server and binds it to a network PORT?
app.listen() listen - servers are listening to the incoming in that port
29
How do you mount a middleware with an Express application?
app.use((req, res)) call the use method
30
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req & res
31
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
32
What does the express.json() middleware do and when would you need it?
it parses incoming requests with JSON payloads and is based on body-parser We need this when we need to receive JSON from the API
33
What is the significance of an HTTP request's method?
It gives specific action to be performed for its method request
34
What does express.static() return?
a path - returns a middleware
35
What is the local __dirname variable in a Node.js module?
name of the current module or the path to the current module
36
What does the join() method of Node's path module do?
joins all given path segments together
37
What does fetch() return?
a Promise that resolves a Response object
38
What is the default request method used by fetch()?
GET
39
How do you specify the request method (GET, POST, etc.) when calling fetch?
fetch(' ', { method: ' '});
40
When does React call a component's componentDidMount method?
immediately after a component is mounted (inserted into the tree).
41
Name three React.Component lifecycle methods.
componentDidMount() componentDidUpdate() componentWillUnmount()
42
How do you pass data to a child component?