Skip to content

Commit

Permalink
doc: add code example to http.createServer method
Browse files Browse the repository at this point in the history
PR-URL: #39455
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
juanarbol authored and targos committed Sep 4, 2021
1 parent fdcc572 commit a437de3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/api/http.md
Expand Up @@ -2626,6 +2626,37 @@ Returns a new instance of [`http.Server`][].
The `requestListener` is a function which is automatically
added to the [`'request'`][] event.

```cjs
const http = require('http');

// Create a local server to receive data from
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
data: 'Hello World!'
}));
});

server.listen(8000);
```

```cjs
const http = require('http');

// Create a local server to receive data from
const server = http.createServer();

// Listen to the request event
server.on('request', (request, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
data: 'Hello World!'
}));
});

server.listen(8000);
```

## `http.get(options[, callback])`
## `http.get(url[, options][, callback])`
<!-- YAML
Expand Down

0 comments on commit a437de3

Please sign in to comment.