Mô-đun URL Node.js
Thí dụ
Phân tích cú pháp chuỗi url thành một đối tượng URL và trích xuất thuộc tính href:
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var q =
url.parse(req.url, true);
res.write(q.href);
res.end();
}).listen(8080);
Định nghĩa và Cách sử dụng
Mô-đun URL cung cấp cách phân tích cú pháp chuỗi URL.
Cú pháp
Cú pháp để bao gồm mô-đun url trong ứng dụng của bạn:
var url = require('url');
Phương thức URL
Method | Description |
---|---|
url.format() | Returns a formatted URL string |
url.parse() | Returns a URL object |
url.resolve() | Resolves a URL |