Express JS: Web Framework For Node JS
Express.js, or simply Express, is a back-end web application framework for building RESTful APIs with Node.js, released as free and open-source software under the MIT License. It is designed for building web applications and APIs. It has been called the de facto standard server framework for Express JS: Web Framework For Node JS
The original author, TJ Holowaychuk, described it as a Sinatra-inspired server, meaning that it is relatively minimal with many features available as plugins. Express is the back-end component of popular development stacks like the MEAN, MERN or MEVN stack, MongoDB database software and a JavaScript front-end framework or library.
Note: Level up your JavaScript skills with React JS Training in Pune with our comprehensive training. Master the language and unlock endless development possibilities. Join us now!
Express.js was founded by TJ Holowaychuk. The first release, according to Express.js’s GitHub repository, was on 22 May 2010. Version 0.12
In June 2014, the rights to manage the project were acquired by StrongLoop. StrongLoop was acquired by IBM in September 2015; in January 2016, IBM announced that it would place Express.js under the stewardship of the Node.js Foundation incubator.
For Free Demo classes Call: 8237077325
Registration Link: Click Here!
Web Applications
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
APIs
With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.
Performance
Express provides a thin layer of fundamental web application features, without obscuring Node.js features that you know and love.
Frameworks
Many popular frameworks are based on Express.
For Free Demo classes Call: 8237077325
Registration Link: Click Here!
Installing
Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.
Hello world example
const express = require(‘express’)
const app = express()
const port = 3000
app.get(‘/’, (req, res) => {
res.send(‘Hello World!’)
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Routing
Routing refers to how an application’s endpoints (URIs) respond to client requests. For an introduction to routing, see Basic routing.
You define routing using methods of the Express app object that correspond to HTTP methods; for example, app.get() to handle GET requests and app.post to handle POST requests. For a full list, see app.METHOD. You can also use app.all() to handle all HTTP methods and app.use() to specify middleware as the callback function (See Using middleware for details).
These routing methods specify a callback function (sometimes called “handler functions”) called when the application receives a request to the specified route (endpoint) and HTTP method. In other words, the application “listens” for requests that match the specified route(s) and method(s), and when it detects a match, it calls the specified callback function.
In fact, the routing methods can have more than one callback function as arguments. With multiple callback functions, it is important to provide next as an argument to the callback function and then call next() within the body of the function to hand off control to the next callback.
The following code is an example of a very basic route.
For Free Demo classes Call: 8237077325
Registration Link: Click Here!
Route paths
Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions.
The characters ?, +, *, and () are subsets of their regular expression counterparts. The hyphen (-) and the dot (.) are interpreted literally by string-based paths.
If you need to use the dollar character ($) in a path string, enclose it escaped within ([ and ]). For example, the path string for requests at “/data/$book”, would be “/data/([\$])book”.
Author:-
Vaibhav Joshi
Call the Trainer and Book your free demo Class For JavaScript Call now!!!
| SevenMentor Pvt Ltd.
© Copyright 2021 | SevenMentor Pvt Ltd.