Express Notes
Express Notes
js
- Developed by TJ Holowaychuk in Nov 2010
- Is a web application framework for Node.js
- Free and open source software
- License under MIT
- Built on the top of the Node.js that helps manage a server and
routes.
Features:
- Facilitates the rapid development
- Allows to set up middleware to respond to HTTP Requests
- Defines a routing table
- Allows to dynamically render HTML Pages
- Uses template engines
Installation:
Node.js should be installed on your machine.
1. Install express-generator
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
3. Install node libraries:
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
6. Go to browser and write localhost:3000 in the address bar to execute the
express code.
1. Uninstall jade
2. Install hbs
npm install hbs --save
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
4. Go to view folder change all jade files by hbs.
5. Remove all jade code and wite hbs code.
Views/layout.hbs
Views/Index.hbs
Routes/index.js
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Express.js Request Object:
The express.js request object represents the HTTP request and has properties
for the request query string, parameters, body, HTTP headers, and so on.
Syntax:
// --
})
The Response object (res) specifies the HTTP response which is sent by an
Express app when it gets an HTTP request.
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Response End method:
This method redirects to the URL derived from the specified path, with
specified HTTP status
Syntax: res.redirect([status,] path)
This method renders a view and sends the rendered HTML string to the client.
Syntax: res.render(view [, locals] [, callback])
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Let's take an example to demonstrate GET method:
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Pattern Matched Routes:-
This will only match the requests that have a 5-digit long id.
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.
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Let's take an example to demonstrate POST method.
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038
Infoway Technologies, 3rd Floor Commerce Centre, Rambaug Colony, Paud Road Pune 411038