You are on page 1of 4

NODEJS

NodeJS - NodeJS is Open source cross-platform


javascript library to create the server side web applications
Real-time web applications, Network applications
it is based on event-driven architecture

NodeJS is generally fast, rarely blocks, great concurrency

Working --> Clients send requests to webserver to interact with web applications
--> Requests like - Querying, Deleting, updating, retrieving the incoming
data

NodeJS is a Single threaded process, under typical web loads we come to know the
performance & scalabiliy of web application without using different threads.
--> To support the asynchronous processing which provides high performance &
effeciency to its application in High load

--> Callback function in NodeJS


It is called after a given task, it allows other code to be run in the meantime to
prevent blocking
All APIs of node are written to support callbacks

Advantages of Callback
a. control flow logic is more specified
b. Coupling is low(component of a code about inner workings of another component of
code)
c. Improved readability(Maintainance of the Code)

A. Backend(Server Side Application) ---- Frontend(client side Application)


B. Everything the happens the BTS ---- Users can interact with web application
C. Java, PHP, Python, NodeJS ---- Angular, React, HTML, CSS

NPM(Node Package Manager) - responsible for managing all the packages & modules
present in NodeJS
A. Provides online repositries for NodeJS(search.nodeJS.org)
B. Provides command line utility to install NodeJS packages

Modules of NodeJS
Modules are like JS libraries that can be include a set of functions
require() function
Modules --> HTTP(includes classes, methods, events to create a NodeJS HTTP server)
util(utility functions)
url(URL parsing)
fs(file operations)
stream(methods to handle streaming data)
zlib(to compress or decompress files)

NodeJS is very fast & ebvcent baserd model


Better synchnorization of code between client & server
Easy for developers to understand the JS libaries

MongoDB

ExpressJS & Mongoose - common libraries

package.json file - Heart of a NodeJS system - file holds the metadata for a
particular project (npm init)

STREAMS in nodeJS
Redable - to read th opertion
writable - to write the operstion
Duplex - can do both like read & write the operation
Trasnform - type of duplex stream where th output is computed based on input

Handle asynchronous errors

a. Handle error using callback


b. Handle Promise rejection

Handle error using callback: A callback function is to perform some operation after
the function execution is completed. We can call our callback function after an
asynchronous operation is completed.

Handle Promise rejection: Promise in Node.js is a way to handle asynchronous


operations. Where we return a promise from an asynchronous function, it can later
be consumed using then() method or async/await to get the final value

Middleware in NodeJS --> middleware is a function that recieves the request and
response object.

a. Execute any code


b. Update or modify the request and the response objects
c. Finish the request-response cycle
d. we can call the next middleware also

PROMISES --> is esentially an improvement of callbacks that manage all asynchronous


data activities

3 Types - resolved, rejected & Pending

ASYNC - The async function declaration creates a binding of a new async function to
a given name
AWAIT - The await keyword is permitted within the function body, enabling
asynchronous, promise-based behavior to be written in a cleaner style

Timing Features -
setTimeout/clearTimeout
setInterval/clearInterval
setImmediate/clearImmediate

Asynchronous/Non-Blocking functions -
a. Asynchronous - the program may not execute line by line
b. Non-blocking - the program does not block the further operations

Synchronous/blocking Function -
a. Blocking - blocking the further operation until the current operation completes.
b. Synchronous - the program executes line by line.

== --> compare between only values


=== --> compare between values & datatypes.

HTTP --> it handles the request and response numbers

REST API - Representational State Transfer - helps to create web server - API will
retrieve the data from the data source & sends back as a request

Dependencies of NodeJS

1 Express
2 Lodash
3 Body-Parser
4 Axios
5 Mongoose
6 Nodemon
7 Bcrypt
8 JWT(JSON web token)
9 Moment
10 Dotenv

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MONGODB

MOngoDB is a opensource NoSQLdocument oriented database tht stores data in JSON


like documents
Easy scalability & document oriented database.
It is designed to handle large volumes of unstructured dats

b. Document in MongoDB
A Document is a set of key value pairs stored in BSON format in MongoDB
BSON is binart representation of JSON.

C. Collection in MongoDB
Collection in MongoDB is a group of documents that share a similar structure. it is
equivalent to a table in relational database

D. Replica set in MongoDB


It is a group of MongoDB servers that stores the same data to provide redundancy
and high availability.

E. Sharding
it is a method of partitioning the data across multiple servers to improve
performance & scalability.

F. Indexing
The process of creating an index on a field in a collection to improve query
performance.

Types -- Single filed, Compound, Muklti Key, Text

G. Update & Save

GridFS
It is a specification for storing & retriving large files, such as images & videos

Primary Key --> Unique identifier for a document


Secondary Key --> Indexing & querying data

MongoDB schema changes


It allows flexible schemas & schemas changes can be made without affecting existing
data.

Difference between Join & a lookup


Join - combining the data from multiple collections
Lookup - Retrieving related data from another collection.

You might also like