Express js: The Ultimate Beginner's Guide to Learn Express js Step by Step 2020 (2st Edition)


var express = require ("express")


Download 316.23 Kb.
Pdf ko'rish
bet4/4
Sana15.08.2023
Hajmi316.23 Kb.
#1667262
1   2   3   4
Bog'liq
Express JS

var express = require ("express");
 
Now let's create a new Express application, which is the server that runs our
entire blog. Express is created simply by calling the express function we
just created:
var express = require ("express");
var app = express ();
The main page of the blog is usually on the root link of the site, which is
expressed in /, we will ask our application to respond to requests that link to
this link by displaying an HTML page containing the last 10 posts arranged
according to the date of writing from the most recent to the oldest:
var express = require ("express");
var app = express ();
 


app.get ("/", function (request, response) {
// Submit HTML
});
To let the page be sent aside and to understand how Express is used, each
Express application has four functions that are used to receive and route
requests: get, post, put, and del. These functions correspond to common
HTTP verbs. But what are HTTP verbs?


How does HTTP work?
Each time you visit a web page, your browser sends a request to the GET
for the content in the link you typed to the server hosting the site. This
HTTP request is similar to the following example (intentionally simplified):
GET www.myblog.com/hello-world HTTP / 1.1
Accept: text / html
Accept-Language: ar-sy, ar;
User-Agent: Mozilla / 5.0 (X11; Linux x86_64; rv: 34.0) Gecko /
20100101 Firefox / 34.0
The Accept and Accept-Language ... fields are called Request Headings,
and each header has a meaning for the server that receives the request. For
example, the browser in the User-Agent field identifies itself, which allows
the server to send a customized answer to each browser (for example, if
desired). In the Accept-Language field, the browser sends the languages
that the user wants to see the answer in. The server sends the page in Arabic
(Syria) ar-sy in our case if it is available, or in Arabic as a second option ...
and so on. The server responds to the request with an HTTP Response
similar to our example:
HTTP / 1.1 200 OK
Content-Type: text / xml; charset = utf-8
Content-Length: 3918




My Blog - Hello world!


Welcome to my humble blog!
" + posts.map (function (post) {return "
  • " + post.title
    + "
  • ";}). join ("") + " " + posts.map (function (post) {return "
  • " + post.title
    + "
  • ";}). join ("") + " " + posts.map (function (post) {return "
  • " + post.title
    + "
  • ";}). join ("") + "
    Download 316.23 Kb.

    Do'stlaringiz bilan baham:
    1   2   3   4




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
    ma'muriyatiga murojaat qiling