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 jasnell committed Jul 28, 2021
1 parent 3f0b623 commit 984f7a0
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 @@ -2693,6 +2693,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 984f7a0

Please sign in to comment.