2023-02-26 01:30
This commit is contained in:
23
getting-started/10_http_server.js
Normal file
23
getting-started/10_http_server.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const http = require('http');
|
||||
const port = 19090;
|
||||
|
||||
const server = http.createServer((req, resp) => {
|
||||
let data = [];
|
||||
req.on('data', (chunk) => {
|
||||
data.push(chunk);
|
||||
});
|
||||
req.on('end', () => {
|
||||
resp.statusCode = 200;
|
||||
resp.setHeader('Content-Type', 'text/html');
|
||||
resp.end(`<p>Hello, <b>${JSON.parse(data).message}</b>!</p>`);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
server.listen(port, () => {
|
||||
console.log('listening on ' + port);
|
||||
});
|
||||
process.on('SIGINT', () => {
|
||||
console.log('closing.. ');
|
||||
server.close();
|
||||
});
|
||||
Reference in New Issue
Block a user