Node Flashcards
What is Node.js?
a program that allows JavaScript to be run outside of a web browser. Node.js is powered by V8; the same JavaScript engine in the Google Chrome browser. It is free, open-source software and its source code is available on GitHub.
What can Node.js be used for?
It is commonly used to build scalable back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
A read–eval–print loop (REPL), also 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
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Node.js, PHP, Ruby, Python, Java
What is a computer process?
the instance of a computer program that is being executed by one or many threads.
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.
What is the process object in a Node.js program?
a global that provides information about, and control over, the current Node.js process.
How do you access the process object in a Node.js program?
You can access it directly as it is a global object which means it is available to all Node.js applications
What is the data type of process.argv in Node.js?
object
What is a JavaScript module?
A single .js file
What values are passed into a Node.js module’s local scope?
\_\_dirname \_\_filename exports module require(id)
Give two examples of truly global variables in a Node.js program.
AbortSignal
clearImmediate(immediateObject)
What is the purpose of module.exports in a Node.js module?
To allow a module to export functions or variables in which another module can import it through require() in Node.js
How do you import functionality into a Node.js module from another Node.js module?
You export the functionality you need by assigning the value of the functionality to the export object. You then import the functionality by assigning the return of the require function to a local variable in your destination module.
What is the JavaScript Event Loop?
one of the four major concepts that sets JavaScript apart from many other languages. The order is a callback function is added to the stack but is then popped off and sent to the web API. It is then sent to the event queue when it will wait to be called. Once the call stack is empty, the first item in the event queue is pushed to the stack and execute.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking is when the code has to wait on a function to execute fully first before the rest of the code can run. Non-blocking is when the the function is sent to another thread so the code can continue running without waiting
What is a directory?
AKA folders. It allow the user to group files into separate collections
What is a relative file path?
The path to a specific file relative to the current directory
What is an absolute file path?
The path to a specific file from the root directory
What module does Node.js include for manipulating the file system?
File System 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?
asynchronous
What are default params?
When defining a function, you can set a parameter to use a default value in case if the function is called without an argument.
Ex: function square(a=6, b) {
random code
}
What is a spread in function calls?
It expands an iterable (array, string, etc) into a list of arguments
Ex:
const nums = [1, 2, 3];
Math.max(…nums);
// This returns 3
What is a spread in array literals?
It creates a new array using an existing array. Spreads the elements from one array into a new array.
Ex: const nums1 = [1, 2, 3]; const nums2 = [a, b, c]; const nums3 = [...nums1, nums2]; //nums3 = [1, 2, 3, a, b, c]
What is a spread in Javascript?
The spread syntax ( … ) allows an iterable, such as arrays or strings, to be expanded in usage as arguments for function calls, or elements for arrays
What is a spread in object literals?
It copies properties from one object into another object.
Ex: const feline = { legs: 4, family: 'Felidae' }; const lion = { ...feline, genus: 'Panthera' }; //lion = {legs: 4, family: 'Felidae', genus: 'Pantera' };
What are rest params?
It collects all remaining arguments into an actual array
What is NPM?
npm is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.
What is a package?
bits of reusable code from the npm repository
How can you create a package.json with npm?
npm init –yes
What is a dependency and how to you add one to a package?
A dependency is another package that your package needs in order to work.
You add one by using the npm install command in Node.
What happens when you add a dependency to a package with npm?
The package.json file is updated to include the dependency and a node_modules directory is added with the dependency package installed
How do you add express to your package dependencies?
Install it through npm ie npm install express
What Express application method starts the server and binds it to a network PORT?
the listen method ie app.listen
How does array destructuring work?
const score = [10, 8, 5, 4, 1] const [gold, silver, bronze] = scores;
How does object destructuring work?
const runner { first: "Eliud", last: "Kipchoge", country: "Kenya", title: "Elder of the Order of the Golden Heart of Kenya" } const {first, last, country } = runner;
const {title: otherName} = runner; // this destructures the title property from the object but assigns it to a variable named otherName ie this allows us to rename the variables
//NOTE: Default values can be assigned to variables if there isn’t a corresponding property from the object
first; //”Eliud”
last; //”Kipchoge”
country; //”Kenya”
How does param destructuring work?
const person1 = { firstName: 'Jimmy', lastName: 'Smith', age: 25 }
function fullName ( { firstName, lastName } ) { return ${firstName} ${lastName}; }
What is a client?
A service requester like a browser
What is a server?
Provider of 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?
A start-line describing the requests to be implemented,
What is on the first line of an HTTP response message?
A start-line declaring the status of a request on whether if it was successful or a failure
What are HTTP headers?
Information in an HTTP message specifying the request, or describing the body included in the message.
Is a body required for a valid HTTP message?
No
How do you mount a middleware with an Express application?
Bind the middleware by using the app.use() and app.METHOD() functions
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the request object, the response object, and the next middleware function of the cycle
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?
It returns middleware that only parses incoming requests with JSON payloads. This allows the app to already have JSON data that has already been parsed to use.
What is the significance of an HTTP request’s method?
It gives the app instruction on what the user’s request wants