Skip to content

Commit

Permalink
chore: synced translations from crowdin [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nodejs-crowdin committed Oct 17, 2024
1 parent 720b889 commit b55aa03
Showing 1 changed file with 81 additions and 88 deletions.
169 changes: 81 additions & 88 deletions apps/site/pages/zh-tw/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ layout: home
<div>
<h1 className="special">隨時隨地執行 JavaScript</h1>

Node.js® 是一款免費的跨平台開源 JavaScript 執行環境,供開發者建立伺服器、網頁應用程式、命令列工具與腳本。

Node.js® 是一款免費的跨平台開源 JavaScript 執行環境,供開發者建立伺服器、網頁應用程式、命令列工具與腳本。
</div>

<div>
Expand Down Expand Up @@ -45,93 +44,87 @@ Node.js® 是一款免費的跨平台開源 JavaScript 執行環境,供開發
// server.mjs
import { createServer } from 'node:http';

const server = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
});

// starts a simple http server locally on port 3000
server.listen(3000, '127.0.0.1', () => {
console.log('Listening on 127.0.0.1:3000');
});

// run with `node server.mjs`

````

```js displayName="Write Tests"
// tests.mjs
import assert from 'node:assert';
import test from 'node:test';
test('that 1 is equal 1', () => {
assert.strictEqual(1, 1);
});
test('that throws as 1 is not equal 2', () => {
// throws an exception because 1 != 2
assert.strictEqual(1, 2);
});
// run with `node tests.mjs`
````
```js displayName="Read and Hash a File"
// crypto.mjs
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';

const hasher = createHash('sha1');

hasher.setEncoding('hex');
// ensure you have a `package.json` file for this test!
hasher.write(await readFile('package.json'));
hasher.end();

const fileHash = hasher.read();

// run with `node crypto.mjs`
```

```js displayName="Streams Pipeline"
// streams.mjs
import { pipeline } from 'node:stream/promises';
import { createReadStream, createWriteStream } from 'node:fs';
import { createGzip } from 'node:zlib';

// ensure you have a `package.json` file for this test!
await pipeline(
createReadStream('package.json'),
createGzip(),
createWriteStream('package.json.gz')
);

// run with `node streams.mjs`
```

```js displayName="Work with Threads"
// threads.mjs
import {
Worker,
isMainThread,
workerData,
parentPort,
} from 'node:worker_threads';

if (isMainThread) {
const data = 'some data';
const worker = new Worker(import.meta.filename, { workerData: data });
worker.on('message', msg => console.log('Reply from Thread:', msg));
} else {
const source = workerData;
parentPort.postMessage(btoa(source.toUpperCase()));
}

// run with `node threads.mjs`
```
const server = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
});

// starts a simple http server locally on port 3000
server.listen(3000, '127.0.0.1', () => {
console.log('Listening on 127.0.0.1:3000');
});

// run with `node server.mjs`
```

```js displayName="Write Tests"
// tests.mjs
import assert from 'node:assert';
import test from 'node:test';
test('that 1 is equal 1', () => {
assert.strictEqual(1, 1);
});
test('that throws as 1 is not equal 2', () => {
// throws an exception because 1 != 2
assert.strictEqual(1, 2);
});
// run with `node tests.mjs`
```

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

```js displayName="Streams Pipeline"
// streams.mjs
import { pipeline } from 'node:stream/promises';
import { createReadStream, createWriteStream } from 'node:fs';
import { createGzip } from 'node:zlib';
// ensure you have a `package.json` file for this test!
await pipeline
(
createReadStream('package.json'),
createGzip(),
createWriteStream('package.json.gz')
);
// run with `node streams.mjs`
```

```js displayName="Work with Threads"
// threads.mjs
import { Worker, isMainThread,
workerData, parentPort } from 'node:worker_threads';
if (isMainThread) {
const data = 'some data';
const worker = new Worker(import.meta.filename, { workerData: data });
worker.on('message', msg => console.log('Reply from Thread:', msg));
} else {
const source = workerData;
parentPort.postMessage(btoa(source.toUpperCase()));
}
// run with `node threads.mjs`
```
</div>

我們提供大量[學習資源](/learn),探索 Node.js 的無限潛能。
</section>

0 comments on commit b55aa03

Please sign in to comment.