Node.js Flashcards
What is a CLI?
Command-line interface
Allows users to interact with a computer program by typing in text/commands
What is a GUI?
Graphical user interface
Allows user to interact with electronic devices through graphical icons and audio indicator
Give at least one use case for each of the commands listed in this exercise.
- man
- cat
- ls
- pwd
- echo
- touch
- mkdir
- mv
- rm
- cp
man: man is an interface to the on-line reference manuals
cat: concatenate files and print on the standard output
ls: list directory contents of current directory
pwd: print name of current/working directory
echo: display a line of text
touch: change file to time stamps
mkdir: makes directories
mv: move (rename) files
rm: remove files or directories
cp: copy files & directories
What are the three virtues of a great programmer?
- laziness
- impatience
- hubris
What is Node.js?
Program that allows JavaScript to be run outside of a web browser
What can Node.js be used for?
Used to build back ends for Web applications, command-line programs, or any kind of automation
What is a REPL?
Read-eval-print loop
A simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user
It is a loop because it waits for the input before executing again
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Python, Ruby, Java, Node.js (JavaScript)
What is a computer process?
Instance of a running program
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
Around 600
Why should a full stack Web developer know that computer processes exist?
It is a web developers job to make multiple processes work together to form one application
What is the ‘process’ object in a Node.js program?
The process object is a global object that provides information about, and control over, the current Node.js process
How do you access the ‘process’ object in a Node.js program?
Can be accessed anywhere since it is global
What is the data type of ‘process.argv’ in Node.js?
An array
What is a JavaScript module?
A single .js file
What values are passed into a Node.js module’s local scope?
- exports
- require
- module
- __filename
- __dirname
Give two examples of truly global variables in a Node.js program.
Global
Process
What is the purpose of module.exports in a Node.js module?
It allows us to separate a large code into smaller modules that can be exported when called/needed
How do you import functionality into a Node.js module from another Node.js module?
By using require( )
What is the JavaScript Event Loop?
The event loop is a process that waits for the Call Stack to be clear before pushing callbacks from the Task Queue to the Call Stack.
What is the difference between “blocking” and “non-blocking” with respect to how code is executed?
Blocking - execute synchronously (does one task at a time)
Non-blocking - execute asynchronously (can do another task before previous one is finished)
What is a directory?
Special folder that contains other files
What is a relative file path?
Locates a file or folder on a file system starting from the current directory
What is an absolute file path?
An absolute path always contains the root element and the complete directory list required to locate the file.
Starts with a slash / (represents root)
What module does Node.js include for manipulating the file system?
Fs (file systems) module
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile()
Are file operations using the fs module synchronous or asynchronous?
Asynchronous
What is a client?
Service requesters
What is a server?
Providers of a resource or service
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What is on the first line of an HTTP request message?
An HTTP method- verb like GET, PUT, POST
The Request target - usually a url
The HTTP version - for web development, will always be HTTP/1.1
What is on the first line of an HTTP response message?
Protocol version (usually HTTP/1.1)
Status code
Status text
What are HTTP headers?
HTTP headers are used to pass additional information between the clients and the server through the request and response header.
Metadata about the request or response
Is a body required for a valid HTTP message?
No
GET, HEAD, DELETE, or OPTIONS usually do not have one
What is NPM? (Node Package Manager)
It is a software registry(a database) of public and private packages
3 components:
Website
Command line interface
The registry
What is a package?
A package is a file or directory that is described by a package.json file.
How can you create a package.json with npm?
Run npm init –yes
What is a dependency and how do you add one to a package?
A dependency is another package that your package needs in order to work.
Using npm install on the command line
What happens when you add a dependency to a package with npm?
The package gets downloaded from the registry and into node_modules & it also updates package.json to list the dependencies
How do you add express to your package dependencies?
npm install express
What Express application method starts the server and binds it to a network PORT?
The listen ( ) method
How do you mount a middleware with an Express application?
‘Use’ method of the ‘app’ object
App.use
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
The request and response object
What does the express.json() middleware do and when would you need it?
If the client is sending json in the body of the request, the middleware is responsible for parsing that request value into an object and stick it onto req.body
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
header(‘Content-Type: application/json’)
What is the significance of an HTTP request’s method?
Allows for communication between client and servers
Describes the intent of the client but is arbitrary (random), does not enforce anything
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS)
MySQL, SQL Server by Microsoft, and Oracle
What are some advantages of learning a relational database?
Supports data integrity
Can store and modify data in way that makes data corruption unlikely
It is the mostly used kind of database so understanding how it works as a web developer is important
What is one way to see if PostgreSQL is running?
Open a second terminal and use top command to check if PostgreSQL is running