Node.js Flashcards
What is Node.js?
A program that allows JavaScript to be run outside of a web browser
What can Node.js be used for?
To build back ends for web applications, command-line programs or any kind of automations that devs wish to perform.
What is a REPL?
Read-eval-print loop. It is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user.
When was Node.js created?
It was created May 27, 2009
What back end languages have you heard of?
JavaScript, Java, Python, Ruby, PHP, VBA
What is a computer process?
The instance of a computer program that is being executed by one or many threads (smallest sequence of programmed instructions). It contains the program code and its activity.
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
6
Why should a full stack Web developer know that computer processes exist?
Based on multiple processes to make applications work. Programming server and database.
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 just call the ‘process’ object since it is a global variable or by using require(‘process’).
What is the data type of process.argv in Node.js?
An array of strings
What is a JavaScript module?
It is a file
What values are passed into a Node.js module’s local scope?
File name, dir name, exports, module, require
Give two examples of truly global variables in a Node.js program.
Process and console
What is the purpose of module.exports in a Node.js module?
To be able to access it from another file
How do you import functionality into a Node.js module from another Node.js module?
Using ‘require’ function using the relative file path
What is a directory?
A file containing the list of files and/or directories
What is a relative file path?
Starts with “./” (sibling directory) or “../” (parent directory)
What is an absolute file path?
The full file path from the root directory.
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?
fs.writeFile
Are file operations using the fs module synchronous or asynchronous?
Both synchronous and asynchronous, depending on the method
How do you add express to your package dependencies?
Install npm express
What Express application method starts the server and binds it to a network PORT?
.listen()
How do you mount a middleware with an Express application?
‘Use’ method of the app object.
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Request and response
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?
The express.json parses the incoming json string and attached the object to req.body
What is the significance of an HTTP request’s method?
Desired action to get from the resource. A server can do whatever it wants with the request.