일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- 맵리듀스
- virtual function
- least square
- member function
- kubernetes
- overriding
- Nonlinear Model
- regression
- 비선형 함수
- inheritance
- 최소제곱법
- 선형모델
- local minimum
- Machine learning
- call by value
- Effective C++
- struct
- 지도학습
- MapReduce
- 회귀
- c++
- 비선형모델
- Nonlinear Function
- Overloading
- 회귀학습
- Class
- call by reference
- 딥러닝
- 머신러닝
- Linear Regression
- Today
- Total
J's Study log
[Web] Node.js - URL 본문
URL : http://exampleurl.com:126/main?id=HTML&page=3
protocol : which way of internet to follow [http : HyperText Transfer Protocol]
host : Computer which is connected to internet
port : Web basically use port number '80' as default value
path : means which directory's which file of the computer
query string : passes informations such as what is which page to show, always starts with '?' and value is emphasized
(?id=HTML&page=3 means "id is HTML and page is 3")
By passed requests of client to query string, the server responses.
And developers will make that progress.
var http = require('http');
var fs = require('fs');
var url = require('url');
//create server
var app = http.createServer(function(request,response){
var _url = request.url;
//parsing directory/file name after 'url.'
//var pathname = url.parse(request.url).pathname;
var queryData = url.parse(_url, true).query;
var title = queryData.id;
if(_url == '/'){
title = 'Welcome';
}
if(_url == '/favicon.ico'){
return response.writeHead(404);
}
response.writeHead(200);
var template = `
<!doctype html>
<html>
<head>
<title>${title}</title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="/">Web</a></h1>
<ol>
<li><a href="/?id=list1">list1</a></li>
<li><a href="/?id=list2">list2</a></li>
<li><a href="/?id=list3">list3</a></li>
</ol>
<h2>${title}</h2>
<p>Hypertext Markup Language (HTML) is the standard markup language for
<strong> creating <u>web</u> pages </strong>and web applications.<br>
Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages.<br>
HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.
</p>
<p style="margin-top:45px;">HTML elements are the building blocks of HTML pages.<br>
With HTML constructs, images and other objects,
such as interactive forms, may be embedded into the rendered page.<br>
It provides a means to create structured documents by denoting structural semantics for text
such as headings, paragraphs, lists, links, quotes and other items.<br>
HTML elements are delineated by tags, written using angle brackets.
</p>
</body>
</html>
`;
response.end(template);
});
app.listen(3000);
require() : Node.js use this function to call module.
[line1,2,3]
what is module?
Parsing
[line10]
// urlExmaple.js
var url = require('url');
var parsedObject = url.parse('http://user:pass@host.com:8080/p/a/t/h?query=string#hash');
console.log(parsedObject); // print information of url object
console.log(url.format(parsedObject)); // print url object to string
Result
$ node urlExample.js
{ protocol: 'http:',
slashes: true,
auth: 'user:pass',
host: 'host.com:8080',
port: '8080',
hostname: 'host.com',
hash: '#hash',
search: '?query=string',
query: 'query=string',
pathname: '/p/a/t/h',
path: '/p/a/t/h?query=string',
href: 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash' }
http://user:pass@host.com:8080/p/a/t/h?query=string#hash
Reference List
English : https://millermedeiros.github.io/mdoc/examples/node_api/doc/url.html
'Computer Language > Web' 카테고리의 다른 글
[Web] Node.js - module exports (0) | 2020.07.30 |
---|---|
[Web] Html - Attribute (0) | 2020.07.17 |
[Web] Html - Tags (10) | 2020.07.15 |