Node/Express/Fetch Flashcards
What is Node.js?
Node.js is a program that allows JS to be run outside of a web browser.
What can Node.js be used for?
commonly used to build back ends for web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
read-eval-print loop. termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise. browser console is REPL.
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Scripting Languages: These are interpreted on-the-fly
jit - just in time compilation
JavaScript (jit), Ruby (jit), Elixir, PHP, Python, Perl, Erlang
what to learn after BootCamp: TYPESCRIPT, any other languages job rec.
Memory Managed Languages: These languages are compiled ahead of time
Java/Kotlin, C#, Golang, Haskell, Julia, F#, Fortan
Manual Memory Management: ahead of time compiled (low-level language)
C++, C, Swift, Rust, D, Zig
SQL - for Database
What is the process object in a Node.js program?
The process object in Node. js is a global object that can be accessed inside any module without requiring it
How do you access the process object in a Node.js program?
execute the node command with the js file that has the console.log(process); in it… or maybe process
What is the data type of process.argv in Node.js?
an array of strings.
What is a JavaScript module?
A single JS file.
A file containing related code. technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
What values are passed into a Node.js module’s local scope?
exports (object), require (function), module (object), __filename (string), __dirname (string)
Give two examples of truly global variables in a Node.js program.
console, process, global
What is the purpose of module.exports in a Node.js module?
The main purpose of module. exports is to achieve modular programming. Modular programming refers to separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
How do you import functionality into a Node.js module from another Node.js module?
call the require function and get the relative path as argument and assign it to a variable.
What is the JavaScript Event Loop?
responsible for collecting the event and running when the stack is empty. event loop looks at the task queue and pushes it back to stack when stack is empty (call stack is cleared).
look at stack and look at the task queue, if stack is empty, it takes the first thing on the queue and pushes it on to the stack ONCE everything on the stack is cleared. which effectively runs it. stacks up on task queue(s) / call back queue and pushes it back to stack to be run.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking: synchronous. need to wait for a process to finish before the next line of code runs. it blocks the next code to run until the current is finished. blocking is occupying the call stack so it can’t do anything until it’s cleared. anything occupying the call stack is blocking.
non-blocking: asynchronous callbacks. is able to run other code/thing while it’s running one code/thing.
What is a directory?
it is a file directory
What is a relative file path?
path to somewhere from where the current file
What is an absolute file path?
starts with a root of the file system “/”
What module does Node.js include for manipulating the file system?
fs module.
What method is available in the Node.js fs module for writing data to a file?
writeFile
Are file operations using the fs module synchronous or asynchronous?
both synchronous and asynchronous
How do you add express to your package dependencies?
make sure to create a package.json first with “npm init” command
after that use “npm install express”
What Express application method starts the server and binds it to a network PORT?
listen() method.
var express = require(‘express’)
var app = express()
app.listen(3000)
How do you mount a middleware with an Express application?
use() method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object and response object
req is a data model of HTTP request message (FROMthe client)
res is a data model of the HTTP response message (TO the client)
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json.
What does the express.json() middleware do and when would you need it?
What does the express.json() middleware do and when would you need it?
It parses incoming requests with JSON payloads. Returns middleware that only parses JSON and only looks at requests where the content-type header matches the type option.
What does express.static() return?
method of express object that returns a function.
express.static(publicPath) returns a function
is a built-in middleware function in Express, syntax
express.static( root, [options] )
What is the local __dirname variable in a Node.js module?
absolute path to the current module’s directory
What does the join() method of Node’s path module do?
combines the paths together.
joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path
What does fetch() return?
a promise. promised to get a response (res). a server responded, here is the response message
What is the default request method used by fetch()?
‘GET’ request.
How do you specify the request method (GET, POST, etc.) when calling fetch?
const request = {
method: ‘POST’
};
as [option], a second argument.
When does React call a component’s componentDidMount method?
after the successful render() . it has finished loading the render() method,
Name three React.Component lifecycle methods.
constructor()
render()
componentDidMount()
componentDidUpdate()
componentWillUnmount()
How do you pass data to a child component?
through props
Userlist users(<- this is the prop that will be passed)