Node.js Flashcards
What is the purpose of module.exports in a Node.js module?
To export data from 1 js file to another
How do you import functionality into a Node.js module from another Node.js module?
require();
What is the javaScript Event Loop?
design pattern that waits for and dispatches events or messages
What is the different between blocking and non-blocking with respect to how code is executed?
blocking doesn’t allow other functions to execute
non-blocking does
What is a directory?
folder, collection of files
What is a relative file path?
paths relative to the current working directory
What is an absolute file path?
Complete directory list
What module does Node.js include for manipulating the file system?
File System
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 synchronus or asynchronous?
async
What is a client?
Request and receive services from a server
What is a server?
Provides functions or services
Which HTTP method does a browser issue to a web server when you visit a URL
GET
What is the first line of an HTTP request message?
Start line
http method
What is on the first line of an HTTP response message?
start-line
http method, status
What are HTTP headers?
additional information passed with an HTTP request
Is a body required for a valid HTTP message?
no
What is NPM?
Node Package Manager, provides hosting for packages
What is a package?
file or directory containing Node modules
How can you create a package.json with npm?
init
What is a dependency and how do you add one to a package?
dependencies are packages required by your app.
They must be listed as a dependency in the package.json. Can use npm i
What happens when you add a dependency to a package with npm?
the dependency is downloaded and saved to the package.json
How do you add express to your package dependencies?
npm i 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
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 is the significance of an HTTP request’s method?
Indicate the desired action. I could use the same path, but have different functions based on the request method
What does the express.json() middleware do and when would you need it?
It parses request with json objects. When receiving json objects