Node.js Flashcards

1
Q

What is a CLI?

A

Command line interface
Text based way to talk to a program

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

What is a GUI?

A

Graphical user interface
Aimed at consumers of technology (end users)

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

Man (manual/directions and helpful tools)

A

Man man

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

Cat (concatenate files and prints content into terminal)

A

Cat filename.txt (prints the content of the file)
Cat filename.txt secondfilename.txt anotherfile.txt > new-file-with-all-three-content.txt (makes a new file with the content from the 3 files)

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

ls (lists all the contents of working directory)

A

ls (this lists the contents in the directory, but doesn’t show hidden ones that start with ‘.’)
ls -a (this lists (-a) all files, even the hidden ones)
ls -F (this lists whether the files are directories vs files by showing / after the directory name)
ls fileDirectoryName/ (this lists the files in this directory)
ls fileDirectoryName/fileName.txt

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

pwd (print working directory, prints the current working directory aka where are you right now)

A

pwd (this prints current working directory)
pwd > i-was-here.txt (this writes current working directory into a new file)

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

echo (repeats the text line back into the terminal, console.log for the terminal)

A

echo ‘Hello, World!’ (prints Hello, World! into terminal)
echo ‘Hello, World!’ > hello.txt (assigns the string into a new file)

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

touch (revise timestamp and create file if it doesn’t exist)

A

touch new-file-name.txt (makes new file)
touch workingDirectory/new-file-name.txt (creates new file in the directory)
touch parent/child/grandchild/.gitkeep (creates a new file in the grandchild directory)

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

mkdir (makes new directory)

A

mkdir parent (created a new directory named parent)
mkdir -p parent/child/grandchild (the -p option creates nested parent/child/grandchild directories)

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

mv (move or rename file)

A

mv old-directory-name new-directory-name (changes the old directory name to the new directory name)

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

rm (remove file or directory **permanent and no warning)

A

rm file-name.txt (the file is deleted/removed)
rm -r directory-name/ (the -r command removes the directory and all of its contents)

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

cp (copy a file)

A

cp file-name.txt copy-of-file-name.txt (this copies the file and makes a new file with same content)

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

What are the three virtues of a great programmer?

A
  1. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
  2. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Node.js?

A

Runs Javascript outside of a browser
Mainly used for file system access and network access (and gives up DOM access from JavaScript)
Event driven, like CSS

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

What can Node.js be used for?

A

Backends for web apps (http servers), command lines programs

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

What is a REPL?

A

Read eval print loop
Reads and evaluates the javascript code and then returns the result and then loops meaning it is ready to read code again
I.e. chrome dev tools console

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

When was Node.js created?

A

Nov 2009

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

What back end languages have you heard of?

A

Scripting languages (aka interpreted)
JavaScript, php, ruby, python, lua
JIT (just-in-time-compiled)
JavaScript
Compiled, memory-managed (with a garbage collector)
C# (clr family languages)
C#, F#, visual basic
Java, (jvm/java-virtual-machine family languages)
Kotlin, clojure, groovy,
Compiled, low-level (with no garbage collector)
C, C++, D, zig, rust
Database
Sql

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

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

A

The process object is an instance (global object, kind of like the window object for browser/front-end) of the running program

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

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

A

You can console log the process object into your javascript file and then run the file in the node program via command
JS file contains console.log(process);
Type in command terminal –> node jsFileName.js

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

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

A

Array of strings
Contains the command line arguments passed when the Node.js process was launched
First element is full path to process.execPath
Second element is the path to the JavaScript file being executed
Remaining elements are additional command line arguments

22
Q

What is a JavaScript module?

A

JavaScript module is the file.js
Each file is a small part of the larger picture of the code
Module is the container that contains everything necessary to execute one aspect of the desired functionality

23
Q

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

A

Export
How this module can provide values and functionality to other modules
Require
How this module can pull values and functionality from other modules
Module
Data model for the whole module
__filename
Full path to this file name of where it is
__dirname
Full path to the directory name of where it is

24
Q

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

A

Process, global, console

25
Q

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

A

It stores the function as a value of a named key of the exports key of the module object, so it can be used in another module
module.exports[keyName] = functionName;

Module.exports = {
Add: add,
addSassy: addSassy
}

**This would be to add multiple properties with different function values into the exports property, which can only be stored 1x per module

26
Q

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

A

Assign the object stored from the other module into a variable via require
Const add = require(‘./add’);

27
Q

What is the JavaScript Event Loop?

A

When a code that is not happening immediately runs(like setTimeout or getting ajax request), it gets popped off the call stack and pushed onto the webapis stack, where it is processed. When this is done processing and has an output, it gets pushed onto the task queue. The JavaScript Event Loop sees the items in the task queue and will push the first item onto the call stack ONCE the call stack is EMPTIED.

28
Q

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

A

Blocking codes are code on the call stack which has to be run one at a time and if it’s take a long time, it is “blocking” the other code in the call stack from running
Non-blocking codes are not on the call stack and processed elsewhere and thus do not block the other codes in the call stack from running

29
Q

What is a directory?

A

Directory is the parent container for files which have content

30
Q

What is a relative file path?

A

Relative file path is a url/ that shows the location of the file in comparison to the current file and can only be accessed within the file/program

31
Q

What is an absolute file path?

A

Absolute file path is a url that contains the location of the file starting from the root. It can be used to access the file from the url alone

32
Q

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

A

The File system aka fs module
Const fs = require(‘fs’);

33
Q

What is a client?

A

Some hardware or software that’s requesting information from server

34
Q

What is a server?

A

Some hardware or software that’s providing information from server that was requested
Host = hardware, the actual physical box
Server = computer program (software programs)

35
Q

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

A

‘GET’ request method

36
Q

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

A

HTTP Method
Like get, put, post
Request target
Url (with query strings)
resource/thing you can get
Http version (message format)
Defaults to 1.1

37
Q

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

A

Protocol (version)
Usually http/1.1
Status code
I.e. 404 which means not found, doesn’t exist
Status text
I.e. actual text description saying ‘not found’
Looks like http/1.1 404 not found

38
Q

What are HTTP headers?

A

Meta data about the message exchange between the server and client witten under the first line of the HTTP request or HTTP response message
Additional information that basically describes the original format of the message data and any encoding applied
Like meta information in the head element in html
**we care about Content-Type in the http header of the response message, which will tell us the type of message we received (i.e. application/json; charset=utf-8

39
Q

Is a body required for a valid HTTP message?

A

No
If the response is too long, you should redirect the content into a separate file to not only reduce API usage, but also easier to access the data in a file
I.e. http –body GET https://example.com > index.html

40
Q

What is NPM?

A

World’s largest software registry named Node Package Manager
A way to reuse code shared by other developers and to
share your code with other developers and helps
manage the different versions of code
All packages are defined in files called package.json
The website itself
https://docs.npmjs.com/
The registry - big database of packages that are being shared
The Command Line Interface (CLI) / Npm client
When a developer chooses to publish their code, they
can by publish the code up to the registry via the npm
client which is installed on the computer to, which then
other developers can install the package from the
registry via the npm client to reuse that code

41
Q

What is a package?

A

A directory with one or more files in it that has a package.json with metadata about the package
Doesn’t mean it has to be published to the registry
Helps reuse the package in your code so you don’t have to create one every time
The package/module is the code that is created by someone and then accessed via NPM with the current version(if applicable)

42
Q

How can you create a package.json with npm?

A

Type in the following command:
npm init –yes (or -y)
It could make it without the –yes and type in every initial properties/values

43
Q

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

A

It’s a 3rd party package that is depended on, which is a folder containing a program described by package.json file
Package references used by your library without which it cannot work and must be installed along with your library installation automatically
You can add package by using the install command
npm install (package name)

44
Q

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

A

‘Dependencies’ gets added as a property with an object as a value, which contains jquery(or whatever you installed as a dependent) as a property with the current version number as its value.
Creates a node_modules directory and installs the package and their code into the directory
node_module
jquery
.package-lock.json

45
Q

How do you add express to your package dependencies?

A

Create a package.json with npm init –yes command
Install with npm install express command

46
Q

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

A

Listen method
app.listen([port[,host[,backlog]]][,callback])

47
Q

How do you mount a middleware with an Express application?

A

app.use() or app.get, put or post methods with the first parameter a string of where you want to mount
The first parameter of the path is optional
**Like addEventListener request, when the server receives this request, what do you want to do

48
Q

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

A

Request object
HTTP Request message (data model)
Response object
HTTP response message (control)
Methods, not properties

49
Q

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

A

Content-Type: application/json
**This is written in the header meta data
This is what we’re hoping in receiving, a content type of JSON, but the person who made the code could NOT actually send you JSON if that’s how they structured their code

50
Q

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

A

Semantics only, and expresses the intent of the code block
Reads the request name and finds the same request method that matches and executes the code block (?)
Allows the server what we want to do in response to the request

51
Q

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

A

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