Skip to content

Commit

Permalink
fix: better examples on home (#6457)
Browse files Browse the repository at this point in the history
* fix: better examples on home

* Update pages/en/index.mdx

Signed-off-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>

---------

Signed-off-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
  • Loading branch information
ovflowd and bmuenzenmeyer authored Mar 8, 2024
1 parent be4cb80 commit ec7ec38
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions pages/en/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ layout: home
<section>
<div>
```js displayName="Create an HTTP Server"
// make a file `server.mjs` and run with `node server.mjs`
import { createServer } from 'node:http';

const server = createServer((req, res) => {
Expand All @@ -57,6 +58,7 @@ layout: home
```

```js displayName="Write Tests"
// make a file `tests.mjs` and run with `node tests.mjs`
import assert from 'node:assert';
import test from 'node:test';
Expand All @@ -71,34 +73,37 @@ layout: home
```

```js displayName="Read and Hash a File"
// make a file `crypto.mjs` and run with `node crypto.mjs`
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
const hasher = createHash('sha1');
const fileContent = await readFile('./package.json');
hasher.setEncoding('hex');
hasher.write(fileContent);
// ensure you have a `package.json` file for this test!
hasher.write(await readFile('package.json'));
hasher.end();
const fileHash = hasher.read();
```

```js displayName="Read Streams"
// make a file `streams.mjs` and run with `node streams.mjs`
import { pipeline } from 'node:stream';
import { createReadStream, createWriteStream } from 'node:fs';
const res = await fetch('https://nodejs.org/dist/index.json');
const json = await res.json(); // yields a json object
const readableStream = createReadStream('./package.json');
const writableStream = createWriteStream('./package2.json');
readableStream.setEncoding('utf8');
readableStream.on('data', chunk => writableStream.write(chunk));
import { createGzip } from 'node:zlib';
import { promisify } from 'node:util';
await promisify(pipeline)
( // ensure you have a `package.json` file for this test!
createReadStream('package.json'),
createGzip(),
createWriteStream('package.json')
);
```

```js displayName="Work with Threads"
// make a file `threads.mjs` and run with `node threads.mjs`
import { Worker, isMainThread,
workerData, parentPort } from 'node:worker_threads';
Expand Down

0 comments on commit ec7ec38

Please sign in to comment.