The Node.js® Website
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: better examples on home (#6457)

* 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>

authored by

Claudio W
Brian Muenzenmeyer
and committed by
GitHub
ec7ec38e be4cb80e

+16 -11
+16 -11
pages/en/index.mdx
··· 43 <section> 44 <div> 45 ```js displayName="Create an HTTP Server" 46 import { createServer } from 'node:http'; 47 48 const server = createServer((req, res) => { ··· 57 ``` 58 59 ```js displayName="Write Tests" 60 import assert from 'node:assert'; 61 import test from 'node:test'; 62 ··· 71 ``` 72 73 ```js displayName="Read and Hash a File" 74 import { createHash } from 'node:crypto'; 75 import { readFile } from 'node:fs/promises'; 76 77 const hasher = createHash('sha1'); 78 - const fileContent = await readFile('./package.json'); 79 80 hasher.setEncoding('hex'); 81 - hasher.write(fileContent); 82 hasher.end(); 83 84 const fileHash = hasher.read(); 85 ``` 86 87 ```js displayName="Read Streams" 88 import { createReadStream, createWriteStream } from 'node:fs'; 89 90 - const res = await fetch('https://nodejs.org/dist/index.json'); 91 - const json = await res.json(); // yields a json object 92 - 93 - const readableStream = createReadStream('./package.json'); 94 - const writableStream = createWriteStream('./package2.json'); 95 - 96 - readableStream.setEncoding('utf8'); 97 - 98 - readableStream.on('data', chunk => writableStream.write(chunk)); 99 ``` 100 101 ```js displayName="Work with Threads" 102 import { Worker, isMainThread, 103 workerData, parentPort } from 'node:worker_threads'; 104
··· 43 <section> 44 <div> 45 ```js displayName="Create an HTTP Server" 46 + // make a file `server.mjs` and run with `node server.mjs` 47 import { createServer } from 'node:http'; 48 49 const server = createServer((req, res) => { ··· 58 ``` 59 60 ```js displayName="Write Tests" 61 + // make a file `tests.mjs` and run with `node tests.mjs` 62 import assert from 'node:assert'; 63 import test from 'node:test'; 64 ··· 73 ``` 74 75 ```js displayName="Read and Hash a File" 76 + // make a file `crypto.mjs` and run with `node crypto.mjs` 77 import { createHash } from 'node:crypto'; 78 import { readFile } from 'node:fs/promises'; 79 80 const hasher = createHash('sha1'); 81 82 hasher.setEncoding('hex'); 83 + // ensure you have a `package.json` file for this test! 84 + hasher.write(await readFile('package.json')); 85 hasher.end(); 86 87 const fileHash = hasher.read(); 88 ``` 89 90 ```js displayName="Read Streams" 91 + // make a file `streams.mjs` and run with `node streams.mjs` 92 + import { pipeline } from 'node:stream'; 93 import { createReadStream, createWriteStream } from 'node:fs'; 94 + import { createGzip } from 'node:zlib'; 95 + import { promisify } from 'node:util'; 96 97 + await promisify(pipeline) 98 + ( // ensure you have a `package.json` file for this test! 99 + createReadStream('package.json'), 100 + createGzip(), 101 + createWriteStream('package.json') 102 + ); 103 ``` 104 105 ```js displayName="Work with Threads" 106 + // make a file `threads.mjs` and run with `node threads.mjs` 107 import { Worker, isMainThread, 108 workerData, parentPort } from 'node:worker_threads'; 109