NodeJS
NodeJS
Multi-processing
• In this a single process (parent process) initiates several single-
threaded child processes and distribute incoming requests to
these child processes. Each of the child processes are
responsible for handling single request.
• It is the responsibility of parent process to monitor the load and
decide if processes should be killed or forked.
Multi-threaded
• Unlike Multi-process, it creates multiple single-threaded process.
Hybrid
• It is combination of above two approaches. In this approach
multiple process are created and each process initiates multiple
threads. Each of the threads handles one connection. Using
multiple threads in single process results in less load on system
resource
Examples
3. Lighttpd
The lighttpd, pronounced lighty is also a free web server that is distributed
with the FreeBSD operating system.
• Let's put step 1 and 2 together in a file called main.js and start
our HTTP server as shown below −
• var http = require("http");
• http.createServer(function (request, response) {
• // Send the HTTP header //
• HTTP Status: 200 : OK //
• Content Type: text/plain response.writeHead(200, {'Content-
Type': 'text/plain'});
• // Send the response body as "Hello World" response.end('Hello
World\n'); }).
• listen(8081);
• // Console will print the message console.log('Server running at
http://127.0.0.1:8081/');
Execution
• Now execute the main.js to start the server as
follows −
• $ node main.js
• Verify the Output. Server has started.
• Server running at http://127.0.0.1:8081/
Make a Request to the Node.js Server
• Web or front-end tier - The top tier of the MERN stack is mainly
handled by React.js. It is one of the most prominent used open-
source front-end JavaScript libraries used for building Web
applications.
• It is famous for creating dynamic client-side applications. React
will help you construct complex interfaces by using single
components.
• It also connects those complex interfaces to data available on the
backend server.
• React is used to create mobile applications (React Native) and
web applications.
• React allows the reusability of code and can easily support it,
which has many benefits and is much time saver.
• It permits users to create large web applications that can easily
change the data of the page even without reloading the page.
Architectural Structure of MERN Stack
• Server or middle-tier - It is just next level from the top layer and is mainly
handled by two components of the MERN stack, i.e., Express.js and Node.js.
• These two's components handle it simultaneously because Express.js
maintained the Server-side framework, running inside the Node.js server.
• Express.js is one of the widely used backend development JavaScript
Frameworks.
• It allows developers to spin up robust APIs (Application Programming
Interface) and web servers much easier and simpler.
• It also adds helpful functionalities to Node.js HTTP (HyperText Transfer
Protocol) objects. Whereas on the other hand, Node.js plays a very
important role in itself.
• It is an open-source server environment, and it is a cross-platform runtime
environment for executing JavaScript code outside a browser.
• Node.js continuously uses JavaScript; thus, it's ultimately helpful for a
computer user to quickly create any net service or any net or mobile
application.
Architectural Structure of MERN Stack
• Database as backend tier - It is one of the most important levels of the MERN
Stack and is mainly handled by MongoDB;
• the main role of a database is to store all the data related to your application, for
example - content, statistics, information, user profiles, comments and so on. It
mainly stores all the data for safety purposes.
• It maintains a proper record, which usually returns the data to the user whenever
required. It mainly stores the data in the database.
• It generates two or more replica files of the data so that whenever the system
fails, it can retrieve the exact information or data that the user wanted earlier. It
implies that MongoDB is not based on the table-like relational database structure.
• On the other hand, it provides an altogether different mechanism for the retrieval
and storage of data. Mongo DB is the most popular NoSQL (NoSQL or Non
Structured Query Language) database, an open-source document-oriented
database.
• The term 'NoSQL' typically means a non-relational database that does not require
a fixed schema or proper relational tables to store the necessary data in it.
• MongoDB stores the data in a different format other than the relational tables,
consisting of rows and columns.
MERN STACK
Advantages of MERN Stack
• There are a lot of advantages of MERN Stack, some of them
are mentioned below -
• For a smooth development of any web application or mobile
app, it supports MVC (Model View Controller) architecture;
the main purpose of this architecture is to separate the
presentation details with the business logic.
• It covers all the web development stages starting from front-
end development to backend development with JavaScript.
• It is an open-source framework mainly used to develop web-
based or mobile applications and is supported by the
community.
• It is very fast and efficient compared to MEAN Stack and
mostly suitable for small applications, whereas MEAN Stack
is suitable for developing large applications.