NodeJs Notes
NodeJs Notes
I.BACKEND OVERVIEW
What is Backend?
Any Parts of the Website that the user can’t see, have a lot of logic written and
interact with a database to give the required data to the frontend
The backend of the Website consists of Server Application Database
Server: A server is nothing but a machine connected to a network, and having
an application running on it
Application : Application does the task of receiving requests from Frontend
and giving back responses to Frontend
DataBase: Organized Collection of Data So that data can be easily accessed
and managed
Example : MySqL, DynamoDB,MongoDB
Some backend languages are: Python, PHP, Java, Ruby
What is a Package?
Package: A package in Node. js contains all the files you need for a module.
Modules: are JavaScript libraries that you can include in your project.
What is Express?
Express is a framework built on top of Node.
post request
IV USING MODULES
What are Modules?
small units of independent, reusable code that is desired to be used as the
building blocks.
How to export modules from separate .js files and import them in
server.js?
Code For Exporting Modules from separate.js Files and importing them in
server.js
Blog.js inside blog_modules
The first argument,req, is shorthand for the request object with built-in
properties to access data from the client-side and facilitate HTTP requests.
The res argument is the response object with built-in methods to send data to
the client-side through HTTP requests.
The argument, next, is a function that tells Express.js to continue on to the
following middleware you have configured for your application.
Files : server.js,contestroutes.js,practicseroute.js
Output
/practicse/mocktesthtml
/practicse/mocktestcss
/practicse/hiringcontest
What is bcrypt?
Bcrypt is a popular and trusted method for salt and hashing passwords
What is bcrypt.compare()?
This method compares hashed and plaintext passwords without the salt
string
Socket Programming
I. INTRODUCTION TO SOCKET PROGRAMMING
What is Socket Programming?
A socket Programming is a endpoint of two way Communication link between
two programs running on the network . A socket is bound to a port number so
that the TCP layer can identify the application that data is destined to be sent
to .
What is tcp?
TCP stands for Transmission Control Protocol a communications standard
that enables application programs and computing devices to exchange
messages over a network
OR
TCP is one of the basic standards that define the rules of the internet and is
included within the standards defined by the Internet Engineering Task Force
(IETF).
What is IP?
Every device has an IP address The Internet Protocol (IP) is the method for
sending data from one device to another across the internet. Every device
has an IP address that uniquely identifies it and enables it to communicate
with and exchange data with other devices connected to the internet.
Event Listeners in Nodejs are the same as the callback. A callback function is
called when a function execution is completed
Backend
Connections
III EVENTS IN SOCKET PROGRAMMING
• The Interactions between client and server happen through events .
• One party emit an event and another party will listen .
• And another party do the actions whatsoever the event emitted .
Case when Frontend (Client) and backend (server) both are emitting event
Frontend Code
Backend Code
Browser
Case : Broadcast Message When all the clients connected to the server
received the server event
Frontend Code
Backend Code
Browser
Case: only those users who have joined the room received the message
when any of the room member from the Room send the message(Group
Chat)
Frontend Code
Backend Code
Browser