Exercise 1 Flashcards
What is Node.js
A platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications.
Runtime Environment for JS code.
Minimal overhead
Not a framework, not a language
What is Node.js Non-blocking/Asynchronous Nature about?
- it is a single thread that is used to handle multiple requests
- if a request needs to query a DB then the thread does not wait for the DB to return data, but moves to the next request and handles it
- As soon as the DB result is ready, it is added to the event queue
- node monitors this queue continuously and whenever it finds an event in this queue, it takes and processes it
Node.js event loop
The Node.js event loop is a single-threaded model that allows asynchronous processing. It works by continuously checking the message queue for new messages (also known as “tasks”) and executing them one by one. Once all the tasks are done, the event loop checks the queue again for new messages. This cycle continues until the process is stopped. The event loop provides non-blocking I/O and helps in managing the concurrency in Node.js applications.
callback
A function that is called when a certain event or operation is completed.
when to use node.js?
Real time applications: apps that have to process a high volume of short messages and require low latency
Fast and scalable environment:
- many requests with low response times
When not to use node.js
CPU-heavy jobs:
- Node.js uses only a single CPU core
- CPU-heavy operations will just block incoming requests
Simple Web Applications: Using Node.js would be superfluous for simple HTML apps in which you don’t need a separate API, all data comes directly from the server
install express module
RUN npm install express
install express module and add in package.json
RUN npm install express –save
install express globally
RUN npm install -g express
What is REST API
Representational State Transfer
Is REST API resources based?
Yes. It deals with things instead of actions (like an address)
6 constraints that make a web service a true RESTful API
- Uniform Interface
- Stateless
- Client-server
- Cacheable
- Layered System
- Code on demand (optional)
What is stateless about?
meaning that no client context is stored on the server between requests.
What is client-server about?
RESTful API must have a clear separation of responsibilities between the client and the server. The client is responsible for making requests, while the server is responsible for serving the requested data.
Cacheable
RESTful API must provide explicit and clear indications of whether the response to a request can be cached or not,