Node.js Theory Flashcards
Learn the basic theory surrounding Node.js. Do the labs to learn the code, will more than likely need it in the exam.
What is a Web Server?
A system that listens for and responds to HTTP requests
What to Web Servers typically respond to requests with?
- A web application with an interface (eg a HTML doc)
- A web service. These are resources (eg info on whether a user is registered with a site), commonly in JSON or XML format.
A single server can serve both applications and data.
What is an API?
Application Programming Interface
A way of externally accessing resources made available by a web service
- Typically specify endpoints as URLs
- Interact with endpoints by making HTTP requests
- Requests and responses typically use XML or JSON
We can think of requests to endpoints as being like a function/method call
Name the two key attributes of RESTful APIs
They are stateless
- APIs don’t depend on the server remembering previous interactions with the client
- Requests contain all info necessary to respond
Uniform Interface
- Endpoints provide availability to interact with some collection of resources through some appropriate noun (eg /movies at the end of a URL)
- When a client has a representation of a resource, it should have enough info to modify or delete it
What are the 3 key features of Node.js?
Event driven execution
- When used properly, this allows for thousands of concurrent connections on a single thread
It is JavaScript
- This allows you to use the same language on both client and serverr
Node Package Manager
Should you use Asynchronous Execution loops or Synchronous Execution loops? Why
Asynchronous
Need to use a non-blocking I/O, otherwise functions in the stack that take a long time to execute will block execution for all users
Should you use the main thread for expensive computations?
No, never, and never synchronously wait for a response for some external system.
A function operating on the main thread blocks executions and makes the server unresponsive
What is Express?
A web application framework for node
Allows you to build web applications and services in node
How is data persistence maintained in a Node.js Server?
Node does not store data - it is designed to process HTTP requests.
Need to use a database for this
What is MongoDB?
A document oriented database
How is data stored in MongoDB?
Data is stored in a collection of JSON-like documents
It makes reading and writing from JS straightforward
The structure isn’t constrained - it can change within a collection from document to document