
The path is where the data is located, and the handler is a function of the client’s request and the server’s response. They are frequently used to process user input.ĮxpressJS routes are functions of a path and handler. Post requests update existing data or create new data. A get request responds with data stored on the server and is commonly used to navigate a user to the appropriate web page. Web servers route user requests to send back an appropriate response. RecapĮxpressJS is a NodeJS framework used to create web server software.
Once in the web browser, navigate to: You should see our home page:Ĭlick on the link "Please Login Here!" and navigate to the login page.Įnter a username and password, then submit.Īfter submitting the form, you should see the username and password you entered displayed in the web browser. So far, server.js should look like this: const express = require('express') // Include ExpressJSĬonst app = express() // Create an ExpressJS appĬonst bodyParser = require('body-parser') // MiddlewareĪpp.use(bodyParser.urlencoded(`)) įinally, we are ready to go to a web browser and test our code.
The server will respond to the get request by sending the file ‘/static/login.html’. Res.sendFile(_dirname + '/static/login.html') The server will respond to the get request by sending the file ‘/static/index.html’. A function of request (req) and response (res). Res.sendFile(_dirname + '/static/index.html') Let's start with the route to our home page. The index page only contains a link to the login page: To demonstrate multiple GET routes, we will also create static/index.html. We will save the login form as static/login.html. As is, the form below should be enough to test server-side functionality. If you are also responsible for the front-end code, you will probably want to pretty it up with CSS and add validation or other front-end functionality. Project file structureīefore we get started on our JavaScript code, we will make a simple HTML login form. A route handler can contain one or more functions. When a request is matched to the appropriate route, a function is executed. In return, the server sends a response, such as the user's dashboard.Ī route’s path tells the server where data is located. When a user submits a login form, they send a request back to the server. The server will respond with the appropriate web page data. A request is sent to the server when a user enters a specific URL (say ). The get method fetches data stored on the web server. The 2 types of requests used in this project are GET and POST. Routing ensures client-side requests receive the proper server response.
The client and the server communicate with a request and response structure. Hypertext Transfer Protocol (HTTP) is the set of rules used for website communication. Create an HTML login form and use ExpressJS to set up the appropriate routes to navigate through the site and process the input.