Skip to content

Commit 697bb15

Browse files
committed
express.js server
1 parent 9879f86 commit 697bb15

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const express = require('express');
2+
3+
const app = express();
4+
5+
const hostname = '127.0.0.1';
6+
const port = 3000;
7+
8+
app.get('/', (req, res) => {
9+
res.setHeader('Content-Type', 'application/json');
10+
11+
let body = {
12+
"message": "Hello, world!",
13+
"items": [
14+
"str1",
15+
"str2",
16+
"str3"
17+
]
18+
};
19+
const { headers, method, query, url } = req;
20+
const responseBody = { headers, method, query, url, body };
21+
22+
res.send(JSON.stringify(responseBody));
23+
})
24+
25+
app.listen(port, hostname, () => {
26+
console.log(`Example app listening at http://${hostname}:${port}`);
27+
})

0 commit comments

Comments
 (0)