We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a5d1937 commit c6fd058Copy full SHA for c6fd058
HTTP-SERVER/index.js
@@ -0,0 +1,35 @@
1
+const http = require("http");
2
+
3
+// specific port
4
+const PORT = 3000;
5
6
+const server = http.createServer((req, res) => {
7
+ /*
8
+ // write some headers to response
9
+ res.writeHead(200, {
10
+ "Content-Type": "text/plain",
11
+ });
12
13
+ // ready to complete the response (close response)
14
+ res.end("Hello! Sir Isaac Newton is your friend!");
15
16
+ */
17
18
+ // json response
19
20
+ "Content-Type": "application/json",
21
22
23
+ // JSON.stringify() to convert object into string
24
+ res.end(
25
+ JSON.stringify({
26
+ id: 1,
27
+ name: "Sir Issac Newton",
28
+ })
29
+ );
30
+});
31
32
+// listen to request
33
+server.listen(PORT, () => {
34
+ console.log(`Listening on port ${PORT}...`);
35
0 commit comments