Skip to content

Commit

Permalink
New translations index.mdx (Vietnamese)
Browse files Browse the repository at this point in the history
chore: synced translations from crowdin
  • Loading branch information
nodejs-crowdin committed Mar 3, 2024
1 parent 6741345 commit 782c262
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions pages/vi/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: Run JavaScript Everywhere
layout: home.hbs
---

<section>
<WithBadge section="index" />

<div>
<h1 className="special">Run JavaScript Everywhere</h1>

```
Node.js® is a free, open-source, cross-platform JavaScript runtime
environment that lets developers create servers, web apps,
command line tools and scripts.
```

</div>

<div>
<WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>
{({ release }) => (
<>
<DownloadButton release={release}>Download Node.js (LTS)</DownloadButton>
<small>
Downloads Node.js <b>{release.versionWithPrefix}</b>
<sup title="Downloads a Node.js installer for your current platform">1</sup> with long-term support.
Node.js can also be installed via <a href="/download/package-manager">package managers</a>.
</small>
</>
)}
</WithNodeRelease>
<WithNodeRelease status="Current">
{({ release }) => (
<small>
Want new features sooner?
Get <b>Node.js <DownloadLink release={release}>{release.versionWithPrefix}</DownloadLink></b>
<sup title="Downloads a Node.js installer for your current platform">1</sup> instead.
</small>
)}
</WithNodeRelease>
</div>
</section>

<section>
<div>
```js displayName="Create an HTTP Server"
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');
});
```

```js displayName="Write Tests"
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);
});
```

```js displayName="Read and Hash a File"
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);
hasher.end();

const fileHash = hasher.read();
```

```js displayName="Read Streams"
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));
```

```js displayName="Work with Threads"
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()));
}
```
````
</div>
Learn more what Node.js is able to offer with our [Learning materials](/learn).
</section>

0 comments on commit 782c262

Please sign in to comment.