KEMBAR78
Node - Js Part3 | PDF | Information Technology | Internet
0% found this document useful (0 votes)
10 views12 pages

Node - Js Part3

Node.Js Workshop Powerpoint Presentation

Uploaded by

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

Node - Js Part3

Node.Js Workshop Powerpoint Presentation

Uploaded by

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

Introduction to NPM(Node Package Manager)

● npm is the package manager for Node.js and is currently the


largest software registry containing over 2.1 Million packages.
The npm registry is the center of JavaScript code sharing; to be
used be Open-Source Developers.
● NPM is a tool that comes with Node.js. It is used to install and
manage third-party packages and modules that help us build
applications faster, such as Express.js, Nodemailer, etc.
● Primarily built to download & manage the dependencies of
Node.js packages, it has now also evolved to a tool which can be
used in frontend JavaScript.
● It is free to use and is coupled with the installation of Node.js
and all the npm public software packages can be downloaded
Creating a basic Node.js Project
1. Open Eclipse and change to Node perspective
Window -> Perspective -> Open Perspective -> Other
-> Node

Exploratory
Data
Analysis
(EDA):
• Summarizing and
visualizing
data.
2. Select Window -> Preferences -> Nodeclipse
3. Update Node.js path and Express path according to your install
location.
Node.js path = C:\NodeJS\node.exe Express path = C:\Users\
<yourusername>\AppData\Roaming\npm\node_modules\express-
generator\bin\express-cli.js
4. Click on Apply and then OK
Click File -> New -> Node.js Express Project as shown
below
6. Select the options and type project name. Note that 'ejs' has been
selected as Template Engine.

7. A default NodeJS Express Project is created with the following


structure.
8. Right click on package.json and click on Run As -> npm Install
9. Update app.js to match:

var http = require('http');


var express = require('express');
http.createServer(function handler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
10. Right click on app.js
res.end('Express app and click on
started Run
from As -> Node.js
Eclipse\n'); }).listen(1337,
Application
'127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
11. Open link http://127.0.0.1:1337/ and you’ll see you ‘’Express
app started from Eclipse’ webpage.
Handling requests and responses (HTTP & HTTPS
Calls)
● Performing actions on the UI of the application leads to the
client sending a request messages to the server.

● This request is met with a response that is generated and


returned to the client as a reply to the request message.

● A request usually consists of a request line that has the request


method and requested URL. <request-method> <request-
target>["?"<query>] HTTP/1.1

Request methods can be of the following types:

1. GET - requests that are aimed at retrieving data (representation of state) from
the target.
2. POST – requests for which the target must process the representation defined in
the request according to the rules setup in the target.
3. PUT - requests the target to create or update its state with the representation
defined in the request.
4. DELETE – requests the target to delete its state for the requested
representation.
5. HEAD – requests which retrieve the representation metadata in the response
header, not the entire representation.
Categorizations of request
methods:
1.Safe Methods: Methods which do not intend
any change or effect to the target server are
called Safe Methods. The methods GET, HEAD,
OPTIONS and TRACE are safe methods. Note:-
POST, PUT, DELETE, CONNECT, and PATCH are not
safe methods as the do intend some changes to
the target.

2. Idempotent Methods: Request methods are


Idempotent Methods if multiple requests of that
method have the same effect as a singular
execution. PUT and DELETE along with the Safe
Methods are Idempotent Methods. POST,
CONNECT, and PATCH are not necessarily
idempotent.

3. Cacheable Methods: Request methods are


considered cacheable if responses to these
requests may be stored to be reused. GET, HEAD
and POST are cacheable methods. PUT, DELETE,
Introduction to
Express
Express.js framework works on top of the web server functionalities of
Node.js
It is open source, managed by the NodeJS foundation.
It is a part of the MEAN stack which is used to build web applications.
MEAN is a JavaScript Full Stack solution comprising of:

1. Mongo DB - Database
2. ExpressJS – Web Framework
3. AngularJS – Frontend Framework
4. NodeJS – Application Server
Features of Express.js:
1. Easy organization of functionalities with middleware as well as routing.
2. Adding utilities to HTTP objects
3. Renders dynamic HTTP objects
4. Addition of templating engines
5. Easier usage of static files from within the application

Express.js helps in the development of robust APIs adhering to REST architecture.

It also helps creating real-time applications and Single Page Applications which effortlessly update content on the client-
side dyncamically.Express works between the request and the response as it serves as a Middleware framwork. It helps
handing client requests by intercepting and manipulating client requests and server responses. Middleware is a set of
functions which Express.js utilizes in the routing layer of the application.

Types of Express functions are:


1. Express Application Functions such as app.disabled(), app.all(), app.delete()
2. Express express functions such as express.Router(), express.static()
3. Express request and response functions such as req.app Property, req.acceptsEncodings() res.download() function
4. Express Routing functions such as router.all() and router.METHOD()

You might also like