Node/Express Flashcards
What does express.static() return?
It returns static files such as images, CSS files, and JavaScript files. It’s built-in middleware.
What is the local __dirname variable in a Node.js module?
Path to directory
What does the join() method of Node’s path module do?
Join the paths that are provided in arguments.
express.static(path.join(__dirname, ‘public’))
What does fetch() return?
It returns a promise.
What is the default request method used by fetch()?
Get method
How do you specify the request method (GET, POST, etc.) when calling fetch?
As an argument of fetch method
What is Node.js?
Program that allows JavaScript to be run outside of the browser or program written in C++ and embedded in JavaScript engine.
Definition - Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser
Outside of the browser - not interacting with Web UI (HTML, CSS) It’s backend programming interacting with databases.
What can Node.js be used for?
Backend applications and command-line programs.
What is a REPL?
take data from input and return something.
The Node.js Read-Eval-Print-Loop (REPL) is an interactive shell that processes Node.js expressions. The shell reads JavaScript code entered by users, evaluates the result of interpreting the line of code, prints the result to the user, and loops until the user signals to quit.
When was Node.js created?
2009 Ryan Dehl(was building a website and notice it didn’t scale)
What back end languages have you heard of?
Scripting languages : PHP, PYTHON, RUBY, PERL, JS, LUA System languages: C, C++, Rust, Zig. Byte Code languages Java, C#, Kotlin,
What is a computer process?
Instance of a running program
What is the process object in a Node.js program?
Global object that can be accessed without requiring it.
How do you access the process object in a Node.js program?
Process object is a global object and can be accessed inside any module without requiring it using keyword “process”.
What is the data type of process.argv in Node.js?
The data type of process.argv in Node.js is an array of strings.
Give two examples of truly global variables in a Node.js program.
process, url, console.log,
What is a JavaScript module?
It’s a file with a reusable code which we can use in different file.
What is the purpose of module.exports in a Node.js module?
Purpose of module.exports is to have access to code in different file.
How do you import functionality into a Node.js module from another Node.js module?
Using require function
What is a directory?
Directory lists other directories or files. It points to a location
What is a relative file path?
Relative path points to file which is relative to our current position.
What is an absolute file path?
An absolute path tells all details about directories starting from the root.
What module does Node.js include for manipulating the file system?
fs (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?
both
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking means when execution of additional processes must wait. Non-blocking when execution of additional processes don’t have to wait.
What is a client?
Something(program or person) requests service from a server
What is a server?
Resources provider
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
What is on the first line of an HTTP request message?
HTTP Method, URL(target), protocol version
What is on the first line of an HTTP response messages?
Protocol Version, Status Code, Status text
What are HTTP headers?
Part of HTTP request/response object, contains vital information about http request/response. (string, key-value pairs)
What is NPM?
node package manager for node JavaScript platform.
What is a package?
The package is a file or directory that contains code described by package.json ( package has to have package.json)
How can you create a package.json with npm?
Using command npm init
What is a dependency and how to you add one to a package?
Dependencies are packages needed to run your app. You need to install them using npm install
What happens when you add a dependency to a package with npm?
It will add key-value pair to jason file and let us use code/programs provided by package code
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?
app.listen()
How do you mount a middleware with an Express application?
By using use method. (app.use) optionally adding path and req,res
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req,res object
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?
The method tell the parties involved what kind of activity is occurring…its more semantics
What does the express.json() middleware do and when would you need it?
It parses incoming payload. We need it when receiving data from client(user)
What three things are on the start-line of an HTTP response message?
Protocol version (HTTP/1.1) Status Code, Status text
What are endpoints?
Endpoints are communication channels (to get data) describes in routes. Most endpoints work through http or https
What is routing?
Routing refers to how application’s endpoints (URLs) respond to client requests .
What is event loop?
Event Loop is a mechanism which JavaScript uses to manage executing functions asynchronously. It’s build in libuv library.