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 @@ -2687,6 +2687,37 @@ Returns a new instance of [`http.Server`][].
26872687The ` requestListener ` is a function which is automatically
26882688added to the [ ` 'request' ` ] [ ] event.
26892689
2690+ ``` cjs
2691+ const http = require (' http' );
2692+
2693+ // Create a local server to receive data from
2694+ const server = http .createServer ((req , res ) => {
2695+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2696+ res .end (JSON .stringify ({
2697+ data: ' Hello World!'
2698+ }));
2699+ });
2700+
2701+ server .listen (8000 );
2702+ ```
2703+
2704+ ``` cjs
2705+ const http = require (' http' );
2706+
2707+ // Create a local server to receive data from
2708+ const server = http .createServer ();
2709+
2710+ // Listen to the request event
2711+ server .on (' request' , (request , res ) => {
2712+ res .writeHead (200 , { ' Content-Type' : ' application/json' });
2713+ res .end (JSON .stringify ({
2714+ data: ' Hello World!'
2715+ }));
2716+ });
2717+
2718+ server .listen (8000 );
2719+ ```
2720+
26902721## ` http.get(options[, callback]) `
26912722## ` http.get(url[, options][, callback]) `
26922723<!-- YAML
You can’t perform that action at this time.
0 commit comments