Skip to content

Commit

Permalink
doc: comment the example code
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Jun 6, 2024
1 parent 68c9f55 commit 74638bf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/api/synopsis.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,31 @@ Open `hello-world.js` in any preferred text editor and
paste in the following content:

```js
// Import the 'node:http' (or just 'http') module, which provides functionality to create/request HTTP servers.
const http = require('node:http');

const hostname = '127.0.0.1';
// Define the hostname and port number on which the server will listen for requests.
const hostname = '127.0.0.1'; // localhost
const port = 3000;

// Create a new HTTP server instance using the 'createServer' method.
const server = http.createServer((req, res) => {
// Set the HTTP status code to 200, indicating success.
res.statusCode = 200;

// Set the response header to specify the content type as plain text.
res.setHeader('Content-Type', 'text/plain');

// End the response with the message 'Hello, World!\n'
res.end('Hello, World!\n');
});

// Tell the server to listen for incoming connections on the specified hostname and port.
server.listen(port, hostname, () => {
// Once the server starts listening, log a message to the console indicating the server is running.
console.log(`Server running at http://${hostname}:${port}/`);
});

```

Save the file. Then, in the terminal window, to run the `hello-world.js` file,
Expand Down

0 comments on commit 74638bf

Please sign in to comment.