Express JS
Express JS
CONTENTS
Introduction
Features
Installation
Routing and HTTP methods
Middleware
Templating
Working
Example
Conclusion
References
INTRODUCTION
What is Express ?
• Express.js is a web application framework Developed by
that is built on top of Node JS. TJ Holowaychuk
• Express provides a minimal interface to build
our applications. It provides us the tools that Released in the
are required to build our app. market on 22nd of
• It is flexible as there are numerous modules May, 2010
available on npm, which can be directly
plugged into.
• Why Express ?
https://nodejs.org/en/download/
FIG: Server architecture of Express.js
• Once you are done with Node.js installation, the next step is to
Install Express.
Step 1.
npm init
Step 2.
npm install -g express
Step 3.
npm install express --save
NPM
app.METHOD(PATH, HANDLER)
Four main HTTP methods that can be supplied within the request.
These methods help in specifying the operation requested by the user.
Method Description
The HTTP GET method helps in requesting for the representation of a
1. GET specific resource by the client. The requests having GET just retrieves data
and without causing any effect.
The HTTP POST method helps in requesting the server to accept the data
2. POST that is enclosed within the request as a new object of the resource as
identified by the URI.
The HTTP PUT method helps in requesting the server to accept the data
3. PUT that is enclosed within the request as an alteration to the existing object
which is identified by the provided URI.
The HTTP DELETE method helps in requesting the server to delete a specific
4. DELETE resource from the destination.
MIDDLEWARE
Pug (Jade)
mustache
dust
handlebars
hogan
liquor
toffee
underscore
walrus
whiskers
WORKING
Step 3:
executing common routines (routing)
Routes allow us to script specific actions based on the path. The
options are GET, POST, PUT and DELETE, but we will focus on
GET and POST for now.
Step 4:
ports
Your server has ports that are kind of like the address. Since
your server can handle many types of server-side scripts at
once, you need to tell it where each script should run.
So if you type:
https://localhost:3000/
into your browser, and you are running your Node app, the
server knows to run the specific script. In this case, as soon
as you enter the URL, you will log the message in the
console and be able to use any of your routes.
EXAMPLE