Node.js Flashcards

1
Q

What is Node.js?

A

A program that allows JavaScript to be ran outside of the 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 used to build back ends for web apps, 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 REPL?

A

Read-Evaluate-Print Loop

  • Known as interactive toplevel or language shell
  • Interactive computer programming environment that takes single user inputs, executes it, and returns the result to user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When was Node.js created?

A

Node.js was created in May 27, 2009 by Ryan Dahl

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

Node.js, React.js, MongoDB, Angular, Spring Boot

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

What is a computer process?

A

When a computer program gets executed by one or many computer 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

555 Processes

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 needs all three processes (front-end, back-end, and data storage) need to be working in order for web apps to work

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

A global that provides info 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

Can call process whenever since it’s global

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

An array

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

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

A

An object

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

console

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

What is the typeof and value of exports?

A

object

{ }

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

What is the typeof and value of require?

A
function
Module {
  id: '.',
  path: '/absolute/path/to',
  exports: {},
  parent: null,
  filename: '/absolute/path/to/entry.js',
  loaded: false,
  children: [],
  paths:
   [ '/absolute/path/to/node_modules',
     '/absolute/path/node_modules',
     '/absolute/node_modules',
     '/node_modules' ] }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the typeof and value of module?

A

object

Module {
id: ,
path: ,
exports: { },
filename: ,
loaded: ,
children: [ ],
paths: [ ],
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the typeof and value of __filename?

A

string

directory/directory/fileName

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

What is the typeof and value of __dirname?

A

string

directory/directory/directoryName

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

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

A

To import a specific function from a different .js file into the main .js file.

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

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

A

const functionName = require(./fileName);

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

What is a directory?

A

A folder that holds files denoted by a /

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

What is a relative file path?

A

A relative file path is a portion of the file path, typically when file paths are in the same root directory

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

What is an absolute file path?

A

The full directory with all of its children/grandchildren/etc

Starts with a /

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What module does Node.js include for manipulating the file system?
The fs module
26
How to access fs?
const fs = require('fs');
27
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile
28
Are file operations using the fs module synchronous or asynchronous?
There are both. Synchronous does not take a callback (should never be used on servers) Asynchronous takes a callback
29
What is a client?
Software that requests content/resources from a server. The ones who initiate the communication. Example: You go on a webpage and wait for the server to show the webpage
30
What is a server?
Software that shares content/resources to the client. Waits for the client to send in requests. Example: Loads up a webpage when client is searching a webpage.
31
Which HTTP method does a browser issue a web server when you visit a URL?
GET
32
What is on the first line of an HTTP request message?
HTTP Method, target, and protocol version
33
What is on the first line of an HTTP response message?
Protocol version, status code, and string translation of status code
34
What are HTTP headers?
Meta data that comes with a request or response
35
Is a body required for a valid HTTP message?
Not all requests/responses need a body because there are some methods that just fetch resources and thats it. For responses its because there are status codes that answer the requests without needing a body (201/404)
36
What is a host?
The hardware that can hold server/client software
37
What is NPM?
Node Package Manager World's largest software registry. Used to share and borrow packages. It is made up of: - The website - The CLI - The registry
38
What is a package?
A directory with one or more files that contains reusable code and a package.json file
39
How can you create a package.json with npm?
Go to the directory you want the package in and type in: npm init --yes
40
What is a dependency and how do you add one to a package?
A dependency refers to the package in the library that cannot work without that package. To add one to a package be on the directory that is holding the npm package in the CLI and then type in: npm install dependencyName
41
What happens when you add a dependency to a package with npm?
Loaded into the node modules directory List of dependencies are updated as well
42
What is a registry?
A large public database of JavaScript software and meta-information surrounding it
43
How do you add express to your package dependencies?
npm install express
44
What express application method starts the server and binds it to a network PORT?
The listen() method
45
What is express?
Express is a framework for Node.js. It provides a set of features for web/mobile applications
46
How do you mount a middleware with an Express application?
use method of the app object ``` const express = require('express') const app = express(); ``` app.use((req, res, next) => { console.log('Time: ', Date.now()); next(); });
47
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req and res parameters
48
What is middleware?
Functions that have access to the request object(req), the response object(res), and the next middleware function in the application's request-response cycle.
49
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
app.JSON
50
What does the express.json() middleware do?
Parses incoming requests and returns JSON data into request.body
51
When would you need the express.json() middleware?
To get specific JSON data that matches the request where the content type header matches the type option
52
What is the significance of an HTTP request method?
The form of communication between client and server which decides what action is to be performed
53
What is a webpack?
A module bunder. A tool that lets you bundle JavaScript applications/files
54
How do you add a devDependency to a package?
npm install package-name --save-dev
55
What is an NPM script?
A property in the package.json object that lets you run npm files.
56
How do you execute Webpack with npm run?
Use the property of the scripts object. "scripts": { "build": "webpack" } When on the CLI type in: npm run build
57
What does express.static( ) return?
It returns a middleware function ``` An example of this would be: const middlewareFunction = (req, res, next) => { // code block }; ```
58
What is the local __dirname variable in a Node.js module?
The directory name is the absolute path that the current module is in
59
What does the join( ) method of Node's path module do?
Joins all given path segments together using a platform-specific separator as a delimiter.
60
What does fetch( ) return?
Returns a promise for a response
61
What is the default request method used by fetch( )?
GET
62
How do you specify the request method (GET, POST, etc.) when calling fetch?
Specify in the 2nd part of the argument. const fetchResponsePromise = fetch(resource [,init]) ``` Example: fetch('https://jsonplaceholder.typicode.com/users', { method: 'GET', // or method: 'POST' }) ```