0% found this document useful (0 votes)
5 views25 pages

Aad

The document provides comprehensive notes on advanced application development using Node.js, MongoDB, Express, Angular, and Flutter. It covers installation procedures, fundamental concepts, and practical applications of these technologies, including creating web servers, managing databases, and building user interfaces. Additionally, it includes references for further reading and a detailed explanation of the Node Package Manager (npm).

Uploaded by

goodmood25012006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views25 pages

Aad

The document provides comprehensive notes on advanced application development using Node.js, MongoDB, Express, Angular, and Flutter. It covers installation procedures, fundamental concepts, and practical applications of these technologies, including creating web servers, managing databases, and building user interfaces. Additionally, it includes references for further reading and a detailed explanation of the Node Package Manager (npm).

Uploaded by

goodmood25012006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

SYCS ADVANCED APPLICATION DEVELOPMENT SBA NOTES:

UNITNodIe:js(N):Introduction to Node.js.Installing Node.is.The package.json 1.5

Fille.The
Node.js Event Loop.The I/O Cycle.The Anatomy of a Node.is Module.Creating Node
Modules,Exploring the Node.js HTTP Module.Creating an HTTP Webserver with Node.js
Responding to HTTP Requests.Routing in Node.js.Creating a Sample Node.js
Application. MongoDB(M):Introduction to MongoDB.Installing MongoDB.Using
MongoDB Compass.
Using Mongo Interface.Connecting MongoDB.Creating Schemas and Models.
Shell Querying to Using Documents Usingcreate().Updating
Documents find().Inserting
Docum Using findOneAndUpdate().Deleting Documents Using
ents deleteMany() findOneAndDelete()&
Server-Side Development with Express (E):Introduction to the Express 15
II Framework. Installing and TestingExpress. Creating a Node.js Express App
Restructuring anExpress App.Creating Templates.Using Express
Middleware
Functions.Creating the List Page.Creating the Details Page.Creating the
Edit Page
Creating the AddPage.DeletingData.REST API Basics.Testing
REST APIs Refactoring APIs
Understanding Angular.JS(A):Getting Started with Angular.Creating
an Angular Application.Angular Project File Structure.Anatomy of an
Angular
Component.One-way Data Binding.Two-way Data Binding.Using Nglf
Directive.
Using NgForOf Directive.Anqular Modules.Creating NgModules Using
Angular Router Configuring Templates.Creating Navigations.Working
with Template-driven Forms. Working with Reactive Forms.Validating
Form Data.Services Dependency Injection
(DI).Reading Data from Database.Inserting Data into Database.Updating
Data in the Database.Delete Data from Database.
UNIT III;
Understanding Flutter:Importance of Flutter,Flutter
Framework,Android Studio, Flutter SDK,Installing and Configuring
Flutter SDK.
Dart Programming:main()function,Dart Variables,DartData Types,Dart
Conditional Operators,Control Flow &Loops.Dart Functions -
Functions,Function
Structure,creatinga Function,Function Expression.Object-
Returning Oriented to
Programming(OOP)-Creating a Class,Adding Classes,Class —Getters
Methods
and Setters,Class Inheritance,Abstract Class, Widget,Container Widget
Flutter Widgets Fundamentals:Scaffold
Widget,Image
Column and Row Widgets,Icon Widget,Layouts in Flutter,Card
Widget,Hot Reload and Hot Restart,Stateful and Stateless Widgets
Navigation and Routing:Button Widget,App Structure and
Navigation,Navigate to
a New Screen and Back,Navigate with Named Routes,Send and
Return Data among Screens,Animate a Widget across
Screens,WebView Widget in Flutter
Textbooks:
1.Node.js,MongoDB and Angular Web Development:The definitive guide to
using the MEAN stack to build web applications by Brad
Dayley,Brendan Dayley,Caleb Dayley, Pearson,2018.
2.Beginning Flutter;A Hands On Guide to App Development by
Marco L.Napoli, Wrox,2019

Additional References:
1.Full Stack Javascript Development with Mean -
MongoDB,Express,AngularJS,and Node.JS by Adam Bretz,Colin J
Ihrig,Shroff/SitePoint,2015
2.Practical Flutter by Zammetti Frank,Apress,2019
SADVANCED APPLICATION DEVELOPMENT QBA NOTES!BY.PROF,AJAY PASHANKAR
CHAPTERI:INTRODUCTION TO NODE.JS(N)
Q.Explain Node
Node.is is a development framework based on Google's V8 JavaScript engine.
Therefore,Node.js code is written in JavaScript and then complled intolmachine code by V8 to
execute
Many of your backend services can be written in Node.is,as can the server-side scripts and any
supporting web application functionality.The nice thing about Node.is is that it is all just
so you can easily take functionality from a client-side script and place it in a server-side
the webserver can run directly within the Node.js platform as a Node.is module,so it makes it
easier than,say,Apache at wiring up new services or server-side
The following are just a few reasons why Node.js is a great framework to start
JavaScript end-to-end: One of the biggest advantages to Node.js is that it allows you to
both server-and client-side scripts in JavaScript.There have always been difficulties in
where to put scripting logic.Too much on the client side makes the client cumbersome
unwieldy,but too much on the server side slows down web applications and puts a heavy burden
the webserver.With Node.is you can take JavaScript written on the client and easily adapt it for
server and vice versa.Also,your client developers and server developers will be speaking the same
language.
Event-driven scalability: Node.js applies a different logic to handling web requests.Rather than
havina multiple threads waiting to process web requests,they are processed on the same thread
using a basic event model.This allows Node.is webservers to scale in ways that
webservers never can.This
is discussed in more detail in later chapters.
Extensibility: Node.js has a great following and an active development community.New modules
to extend Node.is functionality are being developed all the time.Also it is simple to install
and include new modules in Node.js,making it easy to extend a Nodejs project to include
new functionality in minutes.
· Time: Let's face it,time is valuable.Node.js is super easy to set up and develop in.In only a few
minutes,you can install Node.is and have a working webserver.

Who Uses
·Node.js quickly gained popularity among a wide variety of companies.These companies use Node.js
first and foremost for scalability but also for ease of maintenance and faster development.The
following are just a few of the companies using the Node.js technology:
·Yahoo!
·L
e Bin eyd
in

.New York Times


Dow Jones
Microsoft
What Is Node.js Used For?
·Node.is can be used for a wide variety of purposes.Because it is based on V8 and has
highiy optimized code to handle HTTP traffic,the most common use is as a
webserver.However,Node.js
can also be used for a variety of other web services such as:
· Web services APIs such as REST
,Real-time multiplayer games
,Backend web services such as cross-domain,server-side requests Web-based applications
Multiclient communication such as IM

What Does Node.is Come With?


Node.js comes with many built-in modules available right out of the box.This book covers
many but not all of these modules:
·A ssertion testing: Allows you to test functionality within your code.
Buffer: Enables interaction with TCP streams and file system operatians.
·C/ C++add-ons: Allows for C or C++code to be used just like any other
Node.isprocesses: Allows you to create child processes.
Child
"Scaling Applications Using Multiple Processors in Node.js."
Cluster: Enables the use of multicore systems.
Command line options: Gives you Node.js commands to use from a terminal.
·
· Console: Gives the user a debugging
Crypto: Allows for the creation of custom encryption."Using Additional Node.js Modules.")
Debugger; Allows debugging of a Node.js file.
Page 4 of
279
www.profajaypashankar.com
EADVANCED APPLICATION DEVELOPMENT Q&A NOTES:BY.PROF.AJAY PASHANKAR
DNS:Allows connections to DNS
Errors: Allows for the handling of
Events: Enables the handling of asynchronous events.(“Using Events,Listeners,Timers,and
errors.
File system:Allows for flle I/O with both synchronous and asynchronous methods.
the Flle System from
Globals:Makes
HTTP: frequently
Enables support used HTTP
for many modules available without having
features.(“Implementing to include
HTTP Servicesthem
in Node.As.”)
HTTPS: Enables HTTP over the TLS/SSL.[
Modules: Provides the module loading system for
Net: Allows the creation of servers and clients.("Implementing Socket Services in
Os: Allows access to the operating system that Node.is is running
Path: Enables
Process: access
Provides to flle and
information directory
and allows control over the current Node.js process.
Query strings: Allows for parsing and formatting URL queries.
Readline: Enables an interface to read from a data stream.
REPL:Allows developers to create a command
Stream: Provides an API to build obiects with the stream interface.
String decoder; Provides an API to decode buffer objects into
Timers: Allows for scheduling functions to be called in the
TLS/SSL:Implements TLS and SSL protocols.
URL:Enables URL resolution and
Utilities: Provides support for various apps and
modules. V8:Exposes
VM:Allows APIsmachine
for a V8 virtual for the to
Node.js version
run and of code.
compile
ZLIB: Enables compression using Gzip and Deflate/Inflate.

O.Explain how to install Node.is?


Installing Node.js
Download Node.js
·Download Node.is from the official Node.is web site: https://nodeis.org
Installation of Node.js on Windows
Setting up the Node Development Environment
The Node can be installed in multiple ways on a computer.The approach used by you depends on
the existing development environment in the system.There are different package installer for
different environments. You can install Node by grabbing a copy of the source code and compiling
the application.Another way of installing Node is by cloning the GIT repository in all the three
environments and then installing it on the system.[
Installing Node On Windows(WINDOWS 10):
You have to follow the following steps to install the Node.js on your Windows:
environment(32-bit&64-bit).An MSl instaner will be uuwiluaueu
Step-1: Downloading the Node.js
A
The C step to install Node.is on windows is to download the installer. Visit the official
first
website i.e)https://nodeis.org/en/download/and download the .msi file according to your system
bewteroe I oeI oWo
Downloads
Download the Node.js soutce code or a pre-buitt installer for your platform,and start devetopine today.
LTS ey

inary
r
macos g
Step-2:Ru
Now nning
you need to the N othe2 ,jsnode.js installer on your PC.You need to follow the following steps for the
install ( ta

instalier click
·Double on the ,msl installer.
The Node.js Setup wizard will open.
.Welcome To Node.js Setup Wizard.
Page 5 of
www.profajaypashankar.com
279
ADVANCED APPLICATION DEVELOPMENT O&A NOTES;BY.PROF,AJAY PASHANKAR
elect "Next"
Node js Setup ×

Welcome to the Node.js Setup


Wizard

The Setup Wizard will install Node.js on your


computer.

Eack Next Cancel


" "
CheckAf" e ccleipctk ge t ts, ndt-hUese icLei neseA eemmentt"(EULA)will open
Select "Next"
得 Nodejs Setup
×
End-User License Agreement
Please read the following license agreement carefully N de
Node.js is licensed for use as follows:

Copyright Node.js contributors.All rights reserved.

Permission is hereby granted,free of charge,to any person


obtaining a copy of this software and associated documentation
files (the
"Software"),to deal in the Software without
restriction,including without limitation the rights to
use,copy,modify,merge,publish, distribute,sublicense,and/or
sell copies of the Software,and to
permit persons to whom the Software is furnished to do so,subject

☑I accept the terms in the License Agreement

Print Back Next Cancel

,Destination Folder

Set the Destination Folder where you want to install Node.js &Select "Next"

Page 6 of 279

www.profaiaypashankar.com
D APPLICATION DEVELOPMENT OAA NOTEL
WANeED APPL OPMENT QBA NGTESi
F hOE,AAAYEASAANKAR
AD ×
on
Destncstom location or dck Next tonstall.
A ade
Nte s to:

C:Program Fles'nodejs\

Change …

Next Cancel
×
·Custom Setup
A ode

subfeatures
up

Ready to Install
Select "Install"

Page 7 of 279

www.profaiaypashankar.com
BY.PROF.AJAY
PASHANKAR VANCED APPLICATION DEVELOPMENT S&A NOTES: ×
×

Ready to install Node.js A


ode
Cick Install to begin the installation.Click Back to review or change any of
your installaton settings,Click Cancel to exit the wizard.

Badk Install Cancel

NOTE:

A prompt saying -"This step requires administrative privileges"will appear.


Authenticate the prompt as an "Administrator"
·Installing Node.js.
Do not close or cancel the installer until the install is complete
Complete the Node.js Setup
Click "Finish"
Nodejs Setup ×

Completed the Node.js Setup Wizard

Click the Finish button to exit the Setup Wizard.

Node.js has been successfully installed.

Bad Finish Cancel

Step 3:Verify that Node.js was properly instaiied or not.


To check that node.js was completely installed on your system or not,you can run the
following command in your command prompt or Windows Powershell and test it:-
C:\Users\Admin>node -v

www.profajaypashankar.com Page 8 of
ON DEVELOPMENT Q&A NOTES: BY.PROF,AJAY PASHANKAR

CED ADDI ICATION DEY.


ncED 1 99. 7]
pompt n 10 . 62 54
ndo ws (Valp o r o n All ri reserved.
ghts

5.

ff node.js was completely installed on your system,the command prompt will print the version ôf
Ehe node.js installed.
Step 4:Updating the Local npm version.
The final step in node.js installed is the updation of your local npm version(if required)-the package
Imanager that comes bundled with Node.js.
You can run the following command,to quickly update the npm
npm install npm -global //Updates the 'CLI'client
NOTE:
You do not need to do anything to the system variables as the windows installer takes care
the system variables itself while
f installing through the .msi installer
of
·If u use any other format o r installing node.js on your PC,you should put the system variable
p a ho fo r as
node.js
PATH:C:|UserslIusername]|AppData\Roaming\npm
C:|Program Fileslnodejs (Path to the nodejs folder)

0.Explain NPM?
Using the Node Package Manager
The Node Package Manager you have already seen is a command-line utility.It allows you to find,
install,remove,publish,and do everything else related to Node Package Modules.The Node
Package Manager provides the link between the Node Package Registry and your development
environment.
The simplest way to really explain the Node Package Manager is to list some of the command-
line options and what they do.You use many of these options in the rest of this chapter and throughout
the book.Table 3.1 lists the Node Package Manager commands.
Table 3.1 npm command-line options(with express as the package,where appropriate)
Page 9 of 279
www.profaiaypashankar.com
npm

LANCED APPLICATION DEVELOPMENT Q&A NOTES; PROF AJAY


PASHANKAR
31
Example
vie
ropriate) npm search
otion Description
earch express
Finds module packages in the repository

linstall
Installs a package either using a
[package.j son file,from the repository,
npm install
or a local location npm install
express
p
m
n ll
express @ ins 0 ta 1.1
npm install
../tModule.tgz
- Installs a package globally
npm install
express -g
remove Removes a module npm remove
[Pack express
Packages the module defined by the
package.json file into a.tgz file npm
Displays module details
npm view
publish [express
Publishes the module defined by a
package.json file to the registry
unpublish
Unpublishes a module you have published
npm unpublish
myModule
[owner
Allows you to add,remove,and list own ers
of a package in the repository npm add
bdayley
myModu
ammand prompt using the npm search <search_string>、command.For example,the following
mand searches for modules related to openssl and displays the results as shown in Figure 3.2:
barch openssl
Page 10 of
www.profajaypashankar.com
SY CS ADVANCED APPLICATION DEVELOPMENT Q&ANOTES: BY.PROF.AJAY
I

PASHANKAR V
co c
NAMF
bignum
DESCRIPTION
Arbitrary-precision integer arithmetic using OpenSSL
c
ertgen Certificate generation library that uses the openssl command
ipherpipe Thin wrapper around openssl for encryption/decryption
sr Read csr file
sr-gen Generates QpenSSL Certificate Signing Requests
rypt extended openss]bindings
xedentropy js //V8 supports custom sources of entropy.//by default
ckbox Simple,strong encryption.

e-hardcoressl HardcoreSSL is a package for obtaining low-level asynchronous


a 0pen5Sl's RSA encrypt/decrypt routines
nss! openss1 wrapper
nss1-wrapper 0pensSL wrapper
OpenSSL's RSA encrypt/decrypt routines
t1 A wrapper for QpenSSl's rsautl
signed Generate self signed certificates private and public
lself ey-decrypt keys Decrypt encrypted ssh private keys
ssh-
k Verification of SSL certificates
ychain OpenSSl Keychain and Key generation module
ssl gen Open5SL Key Generation module
lss1- RSA public/private key crypto
ke Jss¹- gen node.js odule to generate self-signed certificate via openssl
key
lursa
k509-
key
Figuref s
s a2u Searching for Node.js modules from the command prompt
Installing Node Packaged Modules
To use a Node module in your applications,it must first be installed where Node can find it. To install a
Node module,use the npm install'<module_name>command. This downloads the Node module to your
development environment and places it into the node_modules folder where the install command is run.
For example,the following command installs the express module:
npm install express
The output of the npm install command displays the dependency hierarchy installed with the
module.
LFor example,the following code block shows part of the output from installing the express module.
c:\express\example
[email protected]
[email protected]
[email protected]
mime-
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
I`[email protected]
The dependency hierarchy is listed;some of the methods Express requires are
cookie-signature,range-parser,debug,fresh,cookie,and
modules,Each of these was downloaded during the install.Notice that the version of
each dependency module is listed.
Node.js has to be able to handle dependency conflicts.For example,the
module requires cookie 0.3.1,but another module may require cookie
0.3.0.To handle this situation,a separate copy for the cookie module is placed in
each module's folder under another node_modules folder.
To illustrate how modules are stored in a hierarchy,consider the following example
of how express looks on disk.Notice that the cookie and send modules are
located under the express module hierarchy,and that since the send module
requires mime it is located under the send hierarchy:

www.profaiavpashanL
SHANKAR BY.PROF,AJAY EASMAAKAR
ADVANCED APPLICATION DEVELOPMENT QBA NOTES:
Le modules
Lode modules/express
mand ode_modules/express/node_modules/cookie
node_modules/express/node_modules/send
/node_modules/express/node_modules/send/node modules/mime

Q,Explain Package.json?
图 Defining packages with package.json
In every Node application there should be a file in the root folder of the application called Package,json,
This file can contain various metadata about a project,including the packages that it depends on to run,
The following listing shows an example package.
json file that you might find in the root of a new Express project.
{
"name":"application-name",
"version":"0.0.0",
"private":true,
"scripts":{
"start":"node./bin/www"
M
"dependencies":{
"express":"~4.9.0",
"body-parser":"~1.8.1",
"cookie-parser":"~1.3.3",
"morgan":"~1.3.0",

Listing 3.1 Example package.json file in a new Express project


Various metadata defining application Package dependencies needed for application

to
Licensed to Marwk wWwa.tist-oenb o<[email protected]>
"serve-favicon":"~2.1.3",
"debug":"~2.0.0",
"jade":“~1.6.0”
Ⅱ [


This is the file in its entirety,so it's not particularly complex,There's various metadata at the top of
the file followed by the dependencies section.In this default installation of an Express project there
are quite a few dependencies.Express itself is modular so that you can add in components or upgrade
them individually,
WORKING WITH DEPENDENCY VERSIONS IN PACKAGE.JSON
Alongside the name of each dependency is the version number that the application is
going to use.Notice that they're all prefixed with a ~.
Let's take a look at the dependency definition for Express 4.9.0.It specifies a particular p
version at three levels:
Major version (4) e
■Minor version (9)
Patch version (O)
Prefixing the whole version number with a ~is like replacing the patch version with a wildcard,which
means that the application will use the latest patch version available.
This is considered best practice,as patches should only contain fixes that won't have any impact on the
application.But different major and minor versions could well include changes that cause problems
with [the application,so you want to avoid automatically using later versions of these.
What is Node js?
Node js is an open source server environment
Node js is free
It is developed by Ryan Dahl in the year 2009 and v22.4.1 is the latest version of
Node js.Because it is cross-platform one can easily run on
Windows,Linux,Unix,
macOS and more.
Node js uses JavaScript on the server
it runs on Chrome's V8 JavaScript engine.

Why Node.js?
Node js uses asynchronous programming!

Node js is the backbone of modern web development,providing a powerful


environment for server-side scripting.become proficient in building full-
stack applications,we use the Full Stack Development with React &Node
JS

A common task for a web server can be to open a file on the server and return the
content to the client.
Node js has a unique advantage because millions of frontend developers who
write JavaScript for the browser can now write server-side code without needing to
learn a completely new language.Node js is one of the popular choices for
developing
RESTful APls,microservices and web application.

Here is how PHP or ASP handles a file request:

Sends the task to the computer's file system.


Waits while the file system opens and reads the file.
Returns the content to the client.
Ready to handle the next request.
Here is how Node js handles a file request:

Sends the task to the computer's file system.


Ready to handle the next request.
When the file system has opened and read the file,the server returns the content to
the client.
Node js eliminates the waiting,and simply continues with the next request.

How Node.JS Works?


Node js accepts the request from the clients and sends the response,while working
with the request node js handles them with a single thread.To operate VO
operations or requests node js use the concept of threads.Thread is a sequence of
instructions that the server needs to perform.It runs parallel on the server to
provide
the information to multiple clients.Node js is an event loop single-threaded
language.It can handle concurrent requests with a single thread without blocking
it for one request.

Node js runs single-threaded,non-blocking,asynchronous programming,which


is very memory efficient.

What Can Node js Do?


Node js can generate dynamic page content
Node js can create,open,read,write,delete,and close files on the server
Node js can collect form data
Node js can add,delete,modify data in your database
What is a Node,is File?
Node js files contain tasks that will be executed on certain events
A typical event is someone trying to access a port on the server
Node js files must be initiated on the server before having any effect
Node.js files have extension "js"

Application of Node.JS
Node js is suitable for various applications,including:

Real-time chats
Complex single-page applications
Real-time collaboration tools
Streaming apps
JSON APls
Node js is used to build back-end services like APls like Web App,Mobile App
or Web Server.A Web Server will open a file on the server and return the content
to
the client.It's used in production by large companies such as
Paypal,Uber,Netflix, Walmart,and so on.

Node.JS Ecosystem
Node js has a vibrant ecosystem with a plethora of libraries,frameworks,and
9
tools. Here are some key components:

9
npm(Node Package Manager):npm is the default package manager for
Nodejs.It allows developers to install,manage,and share reusable code
packages (called
modules).You can find thousands of open-source packages on the npm registry.
Express js:Express is a popular web application framework for Node,js.It simpifies
routing,middleware handling,and requestresponse management.Many
developers choose Express for building APIs,web servers,and single-page
applications.
Socketio:For real-time communication,Socketio is a go-to library.It enables
bidirectional communication between the server and clients using WebSockets
or fallback mechanisms.
Mongoose:If you're working with MongoDB(a NoSQL database),Mongoose
provides an elegant way to model your data and interact with the database.It
offers schema validation,middleware,and query building.

Installing Node.js
To begin using Node.js,you need to install it on your system.
Verify the installation by running the following command in your terminal or
command prompt:
node -v
This should dispiay the installed version of Node.js.

Create a Node js file named "myfirstjs",and add the following code:

myfrstjs

var http =require(http));

http.createServer(function (req,res){
res.writeHead(200,{Content-Type':'text/html});
res.end(Hello World!!);
}).listen(8080);
Save the file on your computer:C:UserslYour Namelmyfirst.js

The code tells the computer to write "Hello World!"if anyone (e.g.a web
browser) tries to access your computer on port 8080.

Command Line Interface


Node jsfles must be initiated in the "Command Line Interface"program of
your computer.

Navigate to the folder that contains the file "myfirstjs",the command line
interface window should look something like this:

C:lUserslYour Name>_
Initiate the Node,js File
The file you have just created must be initiated by Node js before any action can
take place.
Start your command line interface,write node myfirst js and hit enter:

Initiate "myfirst js":

C:IUserslYour Name>node myfirst.js


Now,your computer works as a server!

If anyone tries to access your computer on port 8080,they will get a "Hello World!"
message in return!

Start your internet browser,and type in the address:http://localhost:8080

Key Features of Node:js:


JavaScript Everywhere:Node js enables developers to use JavaScript across the
entire stack,from front-end to back-end.This consistency simplifies
development and reduces context switching.
Asynchronous Programming Model:Node js uses an event-driven,non-blocking
(asynchronous)l/O model.This allows handling multiple requests simultaneously
without blocking the execution of other tasks.As a result,Node js applications
are highly responsive and efficient.
Fast Execution:Node js leverages the V8 engine,developed by Google,which
compiles and executes JavaScript at lightning speeds.This performance
advantage makes it suitable for real-time applications and microservices,
Large and Active Community:Node.js has a vibrant community of
developers, libraries,and tools.You'll find extensive resources,tutorials,and
support to
enhance your learning experience.
Scalability:Node js is lightweight and scalable,making it an excellent choice for
building real-time applications,RESTful APIs,and microservices.
Cross-Platform Compatibility:Node js runs on Windows,Linux,Unix,macOS,and
more.This flexibility allows developers to write code once and deploy it
anywhere.

What is a Module in Node.js?


Consider modules to be the same as JavaScript libraries,

A set of functions you want to include in your application.

Built-in Modules
Node js has a set of built-in modules which you can use without any further
installation.

Look at our Built-in Modules Reference for a completelist of modules

Include Modules
To include a module,use the require()function with the name of the module:

var http=require(http');
Now your application has access to the HTTP module,and is able to create a
server:

http.createServer(function (req,res){
res.writeHead(200,{Content-Type':"text/html});
res.end(Hello World!!);
}),listen(8080);
Create Your Own Modules
You can create your own modules,and easily include them in your applications.

The following example creates a module that returns a date and time object:

Example
Create a module that returns the current date and time:

exports.myDateTime =function (){


return Date();

Use the exports keyword to make properties and methods available outside
the module fle.

Save the code above in a file called "myfirstmodule,js"

Include Your Own Module


Now you can include and use the module in any of your Node jsfles.

Example
Use the module "myfirstmodule"in a Node js file:

var http =require(http');


var dt=require('/myfirstmodule');

http.createServer(function (req,res){
res.writeHead(200,{Content-Type':text/html});
res.write("The date and time are currently:"+dt.myDateTime());
res.end();
}).listen(8080);
Notice that we use./to locate the module,that means that the module is located
in the same folder as the Node.js file.

Save the code above in a file called "demo_module,js",and initiate the file:

lnitiate demo_module js:

C:IUserslYour Name>node demo_module.js


If you have followed the same steps on your computer,you will see the same
result as the example:http://localhost:8080

You might also like