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
Q

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

A

The fs module

26
Q

How to access fs?

A

const fs = require(‘fs’);

27
Q

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

A

fs.writeFile

28
Q

Are file operations using the fs module synchronous or asynchronous?

A

There are both.

Synchronous does not take a callback
(should never be used on servers)

Asynchronous takes a callback

29
Q

What is a client?

A

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
Q

What is a server?

A

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
Q

Which HTTP method does a browser issue a web server when you visit a URL?

A

GET

32
Q

What is on the first line of an HTTP request message?

A

HTTP Method, target, and protocol version

33
Q

What is on the first line of an HTTP response message?

A

Protocol version, status code, and string translation of status code

34
Q

What are HTTP headers?

A

Meta data that comes with a request or response

35
Q

Is a body required for a valid HTTP message?

A

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
Q

What is a host?

A

The hardware that can hold server/client software

37
Q

What is NPM?

A

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
Q

What is a package?

A

A directory with one or more files that contains reusable code and a package.json file

39
Q

How can you create a package.json with npm?

A

Go to the directory you want the package in and type in:

npm init –yes

40
Q

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

A

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
Q

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

A

Loaded into the node modules directory

List of dependencies are updated as well

42
Q

What is a registry?

A

A large public database of JavaScript software and meta-information surrounding it

43
Q

How do you add express to your package dependencies?

A

npm install express

44
Q

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

A

The listen() method

45
Q

What is express?

A

Express is a framework for Node.js.

It provides a set of features for web/mobile applications

46
Q

How do you mount a middleware with an Express application?

A

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
Q

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

A

req and res parameters

48
Q

What is middleware?

A

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
Q

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

A

app.JSON

50
Q

What does the express.json() middleware do?

A

Parses incoming requests and returns JSON data into request.body

51
Q

When would you need the express.json() middleware?

A

To get specific JSON data that matches the request where the content type header matches the type option

52
Q

What is the significance of an HTTP request method?

A

The form of communication between client and server which decides what action is to be performed

53
Q

What is a webpack?

A

A module bunder.

A tool that lets you bundle JavaScript applications/files

54
Q

How do you add a devDependency to a package?

A

npm install package-name –save-dev

55
Q

What is an NPM script?

A

A property in the package.json object that lets you run npm files.

56
Q

How do you execute Webpack with npm run?

A

Use the property of the scripts object.

“scripts”: {
“build”: “webpack”
}

When on the CLI type in:
npm run build

57
Q

What does express.static( ) return?

A

It returns a middleware function

An example of this would be:
const middlewareFunction = (req, res, next) => {
   // code block
};
58
Q

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

A

The directory name is the absolute path that the current module is in

59
Q

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

A

Joins all given path segments together using a platform-specific separator as a delimiter.

60
Q

What does fetch( ) return?

A

Returns a promise for a response

61
Q

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

A

GET

62
Q

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

A

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'
})