-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (16 loc) · 660 Bytes
/
Copy pathindex.js
File metadata and controls
23 lines (16 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const http = require('http');
const url = require('url');
const server = http.createServer((req, res) => {
//parse url
const parsedUrl = url.parse(req.url, true);
// get the path
const path = parsedUrl.pathname;
const trimmedPath = path.replace(/^\/+|\/+$/g, '');
// Get the query string as an object
const queryStringObject = parsedUrl.query;
// Get the HTTP method
const method = req.method.toLowerCase();
res.setHeader('Content-Type', 'text/html');
res.end('Request pathname: '+trimmedPath+' with HTTP method: '+method+' and this query string: '+ JSON.stringify(queryStringObject));
})
server.listen(3000);