| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f851efd commit 0d34767
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2720,7 +2720,7 @@ The `callback` is invoked with a single argument that is an instance of | |||
| 2720 | 2720 | JSON fetching example: | |
| 2721 | 2721 | ||
| 2722 | 2722 | ```js | |
| 2723 | - http.get('http://nodejs.org/dist/index.json', (res) => { | ||
| 2723 | + http.get('http://localhost:8000/', (res) => { | ||
| 2724 | 2724 | const { statusCode } = res; | |
| 2725 | 2725 | const contentType = res.headers['content-type']; | |
| 2726 | 2726 | ||
@@ -2755,6 +2755,16 @@ http.get('http://nodejs.org/dist/index.json', (res) => { | |||
| 2755 | 2755 | }).on('error', (e) => { | |
| 2756 | 2756 | console.error(`Got error: ${e.message}`); | |
| 2757 | 2757 | }); | |
| 2758 | + | ||
| 2759 | + // Create a local server to receive data from | ||
| 2760 | + const server = http.createServer((req, res) => { | ||
| 2761 | + res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
| 2762 | + res.end(JSON.stringify({ | ||
| 2763 | + data: 'Hello World!' | ||
| 2764 | + })); | ||
| 2765 | + }); | ||
| 2766 | + | ||
| 2767 | + server.listen(8000); | ||
| 2758 | 2768 | ``` | |
| 2759 | 2769 | ||
| 2760 | 2770 | ## `http.globalAgent` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments