File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -2626,6 +2626,37 @@ Returns a new instance of [`http.Server`][].
26262626The ` requestListener ` is a function which is automatically
26272627added to the [ ` 'request' ` ] [ ] event.
26282628
2629+ ``` cjs
2630+ const http = require (' http' );
2631+
2632+ // Create a local server to receive data from
2633+ const server = http .createServer ((req , res ) => {
2634+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2635+ res .end (JSON .stringify ({
2636+ data: ' Hello World!'
2637+ }));
2638+ });
2639+
2640+ server .listen (8000 );
2641+ ```
2642+
2643+ ``` cjs
2644+ const http = require (' http' );
2645+
2646+ // Create a local server to receive data from
2647+ const server = http .createServer ();
2648+
2649+ // Listen to the request event
2650+ server .on (' request' , (request , res ) => {
2651+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2652+ res .end (JSON .stringify ({
2653+ data: ' Hello World!'
2654+ }));
2655+ });
2656+
2657+ server .listen (8000 );
2658+ ```
2659+
26292660## ` http.get(options[, callback]) `
26302661## ` http.get(url[, options][, callback]) `
26312662<!-- YAML
You can’t perform that action at this time.
0 commit comments