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 danielleadams committed Aug 16, 2021
1 parent 110c088 commit 3ff5e15
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,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 3ff5e15

Please sign in to comment.