Domain Name Service helps us to identify webstes using the name like when we go to an website like www.google.com how the web knows what is google.com in this We Request the DNS to get us the server IP address of that particular url and DNS gives us that due to which we are able to Surf www.google.com
Doman Name Entry:->User types an domain
- DNS query:->The browser sends an DNS query to resolve th domain into an IP address
- DNS Server:-> Provides the correct IP address for the domain
- Browser Connects:->The browser uses the IP to connect to the Web server and Loads the Website
- Client Request Initiation: The client (browser) initiates a network call by entering a URL.
- DNS Resolution: The browser contacts a DNS server to get the IP address of the domain.
- TCP Connection: The browser establishes a TCP connection with the server's IP address.
- HTTP Request: The browser sends an HTTP request to the server.
- Server Processing: The server processes the request and prepares a response.
- HTTP Response: The server sends an HTTP response back to the client.
- Network Transmission: The response travels back to the client over the network.
- Client Receives Response: The browser receives and interprets the response.
- Rendering: The browser renders the content of the response and displays it to the user.
- Http (HyperText Transfer Protocol):
a) Facilitates communication between a web browser and a server to transfer web pages. b) Sends data in plain text (no encryption). c) Used for basic website browsing without security.
- HTTPS (HyperText Transfer Protocol Secure):
a) Secure version of HTTP, encrypts data for secure communication.
b) Uses SSL/TLS to encrypt data.
c) Used in online banking,e-commerce etc..
- TCP(Transmission Control Protocol):
a) Establish a connection Before any data is Transferred b) Ensures reliable,ordered and erorr echecking data every over the internet
whenever we want to use an module in node we use the Require keyword modules like:->
-
fs -> used for reading and writing in the files
-
http :->.... learn about node modules more in the future chapter
-
Purpose:-> imports module in NODE.js
-
caching:-> Modules are cached after the first require call
-
.js :->is added automatically and is not needded at the end of the module name
-
Path Resolution:->Node.js searches for module in core ,node_modules,and file paths
WE are going to use the http module to make an server then we will declare an function to get the respnse from the cleint and the response too then going to save the http.createserver in anything then add an listener in that const server
- function RequestListener(req,res){ console.log(req); } const server=http.createServer(RequestListener); server.listen(3000);// Here the 3000 is the port number
we also have to declare an port for that
Think of Node like:
One extremely fast receptionist + a big back-office team
Receptionist = Event Loop (main thread)
Back office = OS / thread pool
Phone calls = Incoming requests
The receptionist:
Takes a request
If it’s quick → handles immediately
If it’s slow → sends it to back office and moves on
That’s how 500k requests don’t crash it.
process.exit();
function RequestListener(req,res){ console.log(req); process.exit(); }
the node is event driven like whenever there is an event occurs
we listen it by using the event listeners and those event listeners
put that task in an qeueu then that task goes into the event the loop
then we get to see the event handler that handles those events
request and events are handled by only on thing and that is event loop
that makes it single threaded (single unit of process)
there are worker threads lets suppose we gete an requests o fetch data from the DB
then the loop will use the worker threads to fetch that data and feed it
-
What V8 Does (Responsibilities):-> Parses JavaScript JIT compiles JS to machine code Executes JS functions Handles: Call Stack Heap Garbage Collection
-
What libuv Does (Responsibilities):-> Event loop Thread pool Async I/O: File system Networking DNS Timers OS-level abstractions (Linux, Windows, macOS)
async code cacn be understood by one line
"le bhai ye request jab kaam hojaye to waapis se call back kardena"
lets suppose in sum.js here we wrote the response alongside the req.on("end"){
beacuse if we didnt do that we will execute the result firstly then we will compute it
that will make an problem there
thats how we use async code;
}
a blocking code blocks the all code that will be in the queue
i will just focus on one line
ex.fs.writeFileSync();this will block all the requests at that time
to make it execute first which is not an good practice
so we have to use the async method that is fs.writeFile();
npm init