Node.js Flashcards
What is a code block? What are some examples of a code block?
section of code enclosed within { }, ex: function, conditional, loop
What is a CLI?
command-line interface, text-based
What is a GUI?
graphical-user interface, graphical icon-based
man
user manual for commands
cat
combine content of files
ls
shows content of directory
pwd
shows current directory
echo
prints out text on terminal, like console.log( )
touch
changes file timestamps, can be used to create a new file
mkdir
creates a new directory
mv
renames or moves a file
rm
deletes a file
cp
copies a file
What are the three virtues of a great programmer?
laziness, impatience, hubris
What is Node.js?
a program that allows JS to be run outside of a web browser
What can Node.js be used for?
it can be used for back-ends for Web applications, command-line programs anything with automation
What is a REPL?
read-eval-print loop
When was Node.js created?
May 27, 2009
What is a computer process?
a process is the instance of a computer program that is being executed by one or many threads
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
480 processes
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
What is the process object in a Node.js program?
a global that provides info about, and control over, the current Node.js process
How do you access the process object in a Node.js program?
with or without require( )
What is the data type of process.argv in Node.js?
an array of strings of the command-line arguments
What is a JavaScript module?
a single .js file
What values are passed into a Node.js module’s local scope?
module, exports, require( ), __dirname, __filename
Give two examples of truly global variables in a Node.js program.
process, global
What is the purpose of module.exports in a Node.js module?
allows you to export functions and objects from a module to be used in another
How do you import functionality into a Node.js module from another Node.js module?
require( relative path to file)
What is the JavaScript Event Loop?
the event loop looks at the call stack and the task queue; if the stack is empty, the event loop pushes the first thing on the queue into the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking means the code is occupying the call stack, non-blocking means the code is a Web API (network, DOM, events) and is pushed to the task queue
What is a directory?
a collection of files
What is a relative file path?
points to a file within the context of the current directory
What is an absolute file path?
points to a file from the root directory
What module does Node.js include for manipulating the file system?
fs
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
What is NPM?
website, CLI, registry that provides a way to reuse code from other developers, to share your code with them, and manage different versions of code
What is a package?
a directory containing a program described by a package.json file, and a package.json file
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?
another package a package needs in order to work, npm install
What happens when you add a dependency to a package with npm?
package.json will be updated to include the dependency and the package for the dependency will be installed to the node_modules directory
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?
app.listen( )
How do you mount a middleware with an Express application?
app.use( )
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req and res
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?
returns a middleware function that parses JSON, attaches data to the body property of the req object, used when expecting requests with JSON
What is the significance of an HTTP request’s method?
describes the action the server has to perform
What does express.static( ) return?
middleware function that serves files within a given root directory
What is the local __dirname variable in a Node.js module?
absolute file path of directory of current module
What does the join() method of Node’s path module do?
join all given path segments