0% found this document useful (0 votes)
77 views

Express JS

Express JS is a web application framework for Node.js that provides a robust set of features for building web and mobile applications. It has advantages like simplicity, flexibility, community support, scalability, and cross-platform functionality. Middleware functions in Express JS allow processing requests and responses by performing tasks or altering them before passing to other routes and controllers.

Uploaded by

coding727tree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Express JS

Express JS is a web application framework for Node.js that provides a robust set of features for building web and mobile applications. It has advantages like simplicity, flexibility, community support, scalability, and cross-platform functionality. Middleware functions in Express JS allow processing requests and responses by performing tasks or altering them before passing to other routes and controllers.

Uploaded by

coding727tree
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1

INTRODUCTION TO EXPRESS JS
WHY EXPRESS IS USED OVER NODE JS ?

JavaScript is a fast, unopinionated, minimalist web framework for Node. js that provides a
robust set of features for web and mobile applications. It has many advantages, such as
simplicity, flexibility, community support, scalability, and cross-platform functionality.

Feature Express JS Node JS

It is used to build web-apps


It is used to build server-side,
Usage using approaches and
input-output, event-driven apps.
principles of Node JS

Level of features More features than Node JS. Fewer features.

Building Block It is built on Node JS It is built on Google’s V8 engine.

Written in JavaScript C, C++, JavaScript

Run-time platform or
Framework/Platform Framework based on Node JS environment designed for server-
side execution of JavaScript.

Controllers Controllers are provided. Controllers are not provided.

Routing Routing is provided. Routing is not provided.

Uses middleware for the


Middleware arrangement of functions Doesn’t use such a provision.
systematically server-side.

Coding time It requires less coding time. It requires more coding time.
2

P ARAMS & Q UERY IN E XPRESS


http://localhost:3000/hello/Rohan?mode=dark

Rohan is Params & mode=dark is Query

C REATING S TATIC W EBSITE


3

REQUEST & REQUEST HANDLING


1.GET REQUEST — get all data

2. POST REQUEST — save data

3. PUT REQUEST — edit data

4. DELETE REQUEST — delete data

1.Get Request ( URL )


Get method facilitates you to send only limited amount of data because data is sent in
the header. It is not secure because data is visible in URL bar.
4

Get Request Limit => Most servers and clients have a limit of 8192 bytes (8 KB), which is usually
configurable somewhere in the server or client settings.

2.Post Request
Post method facilitates you to send large amount of data because data is send in the body. Post
method is secure because data is not visible in URL bar but it is not used as popularly as GET
method. On the other hand GET method is more efficient and used more than POST.
5

Post Request can be tested in POSTMAN/Thunder Client(VS CODE EXTENSION)

C HAINING OF REQUEST

BOTH THE WAY TO WRITE A REQUEST IS RIGHT

https://youtu.be/SksvlZM-5Sk?si=lYvIArX_XxeOPUWW

M IDDLEWARE FUNCTIONS
6

Middleware functions are functions that have access to the request object (req), the response
object (res), and the next function in the application’s request-response cycle.
The next function is a function in the Express router which, when invoked, executes the
middleware succeeding the current middleware.

Middleware functions can perform the following tasks:

1. Execute any code.


2. Make changes to the request and the response objects.
3. End the request-response cycle.
4. Call the next middleware in the stack.
7
8

In Express.js, app.use(express.static(path.join(__dirname, "public"))); is middleware that serves


static files such as images, CSS files, and JavaScript files.

So, when a request is made to your Express server, Express will first check if the requested URL
matches a file in the specified directory (public), and if so, it will serve that file. If not, it will
continue to the next middleware or route handler in the chain. This middleware is commonly
used to serve static assets like HTML, images, CSS, and client-side JavaScript files, making them
accessible to clients when they access your web application.

Creating Own Middleware Functions

If the current middleware function does not end the request-response cycle, it must
call next() to pass control to the next middleware function. Otherwise, the request will be left
hanging.
9

G ET D ATA F ROM E ND P OINT

EXPRESS HANDLE BARS


https://github.com/ericf/express-handlebars

You might also like