NODEjs lecture 5
NODEjs lecture 5
Introduction
Module:5
Contents
• Web Module
• Networking Module
• Node.js with mongodb (self study not for exams)
Web module
• What is a Web Server?
• A Web Server is a software application which handles HTTP
requests sent by the HTTP client, like web browsers, and
returns web pages in response to the clients. Web servers
usually deliver html documents along with images, style
sheets, and scripts.
• Most of the web servers support server-side scripts, using
scripting languages or redirecting the task to an application
server which retrieves data from a database and performs
complex logic and then sends a result to the HTTP client
through the Web server.
• Apache web server is one of the most commonly used web
servers. It is an open source project.
Web Application Architecture
• Client − This layer consists of web browsers, mobile browsers
or applications which can make HTTP requests to the web
server.
• Server − This layer has the Web server which can intercept the
requests made by the clients and pass them the response.
• Business − This layer contains the application server which is
utilized by the web server to do the required processing. This
layer interacts with the data layer via the database or some
external programs.
• Data − This layer contains the databases or any other source
of data.
• 1. Creating a Web Server using Node
• Node.js provides an http module which can be used to create
an HTTP client of a server. In demo is the bare minimum
structure of the HTTP server which listens at 8081 port.
• Refer server.js code in notes
• 2. Creating a Collection
• To create a collection in MongoDB, use
the createCollection() method:
• demo_mongodb_createcollection.js in mongodb folder
Insert
• Insert Into Collection
• To insert a record, or document as it is called in MongoDB, into
a collection, we use the insertOne() method.
• A document in MongoDB is the same as a record in MySQL
• The first parameter of the insertOne() method is an object
containing the name(s) and value(s) of each field in the
document you want to insert.
• Refer demo_mongodb_findone.js
Filter
• Filter the Result
• When finding documents in a collection, you can filter the
result by using a query object.
• The first argument of the find() method is a query object, and
is used to limit the search.
• Refer demo_mongodb_query.js
•Thanks