File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -2693,6 +2693,37 @@ Returns a new instance of [`http.Server`][].
2693
2693
The ` requestListener ` is a function which is automatically
2694
2694
added to the [ ` 'request' ` ] [ ] event.
2695
2695
2696
+ ``` cjs
2697
+ const http = require (' http' );
2698
+
2699
+ // Create a local server to receive data from
2700
+ const server = http .createServer ((req , res ) => {
2701
+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2702
+ res .end (JSON .stringify ({
2703
+ data: ' Hello World!'
2704
+ }));
2705
+ });
2706
+
2707
+ server .listen (8000 );
2708
+ ```
2709
+
2710
+ ``` cjs
2711
+ const http = require (' http' );
2712
+
2713
+ // Create a local server to receive data from
2714
+ const server = http .createServer ();
2715
+
2716
+ // Listen to the request event
2717
+ server .on (' request' , (request , res ) => {
2718
+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2719
+ res .end (JSON .stringify ({
2720
+ data: ' Hello World!'
2721
+ }));
2722
+ });
2723
+
2724
+ server .listen (8000 );
2725
+ ```
2726
+
2696
2727
## ` http.get(options[, callback]) `
2697
2728
## ` http.get(url[, options][, callback]) `
2698
2729
<!-- YAML
You can’t perform that action at this time.
0 commit comments