Skip to content

Node grgtrnhtshsrt

เมื่อเรา Node Built-in Modules เราจะ import modules from node:modules
js
// import fs จาก node:fs
import fs from 'node:fs';

// การอ่านไฟล์
fs.readFile('example.txt', 'utf8', (err, data) => {
  if (err) {
    console.error('Error reading file:', err);
    return;
  }
  console.log('File contents:', data);
  
  // การเขียนไฟล์หลังจากอ่านเสร็จ
  fs.writeFile('example.txt', 'Hello, Node.js ESM!', (err) => {
    if (err) {
      console.error('Error writing file:', err);
      return;
    }
    console.log('File written successfully.');

    // การเช็คว่ามีไฟล์หรือไม่
    fs.access('example.txt', fs.constants.F_OK, (err) => {
      if (err) {
        console.log('File does not exist.');
      } else {
        console.log('File exists.');
      }

      // การลบไฟล์หลังจากเช็ค
      fs.unlink('example.txt', (err) => {
        if (err) {
          console.error('Error deleting file:', err);
          return;
        }
        console.log('File deleted successfully.');
      });
    });
  });
});

Error Handling and Inspection

ModuleDescription
assertให้ฟังก์ชันสำหรับการตรวจสอบ.
domainให้วิธีการจัดการข้อผิดพลาดใน asynchronous.

Data and File Handling

ModuleDescription
bufferให้คลาสสำหรับจัดการข้อมูลไบนารี.
fsให้ฟังก์ชันการทำงานเกี่ยวกับระบบไฟล์.
pathให้ยูทิลิตี้สำหรับการทำงานกับเส้นทางไฟล์และไดเร็กทอรี.
string_decoderให้วิธีการถอดรหัสสตรีมของสตริง.

Process and Networking

ModuleDescription
child_processอนุญาตให้คุณสร้างและติดต่อกับ child processes.
clusterอำนวยความสะดวกในการสร้าง cluster ของ Node.js processes.
netให้ฟังก์ชันการทำงานเกี่ยวกับเครือข่าย.
dgramใช้สำหรับ UDP datagram sockets.
httpให้ฟังก์ชันการทำงานของ HTTP server และ client.
httpsให้ฟังก์ชันการทำงานของ HTTPS server และ client.

Process Management

ModuleDescription
processให้ข้อมูลและควบคุมโปรเซสปัจจุบันของ Node.js.
timersให้ฟังก์ชันสำหรับการจัดตารางเวลาและการจัดการ timers.

Stream Handling

ModuleDescription
streamให้ยูทิลิตี้สำหรับการทำงานกับสตรีม.
readlineให้อินเตอร์เฟซสำหรับอ่านข้อมูลจาก readable stream.

Text and URL Handling

ModuleDescription
querystringให้ยูทิลิตี้สำหรับการแยกวิเคราะห์และจัดรูปแบบ URL query strings.
urlให้ยูทิลิตี้สำหรับการแก้ไขและแยกวิเคราะห์ URL.

Debugging and Output

ModuleDescription
consoleให้ console debugging ที่ง่าย.
inspectorให้ API สำหรับการดีบักแอปพลิเคชัน Node.js.
replให้ Read-Eval-Print Loop (REPL) สำหรับการเขียนโปรแกรมเชิงโต้ตอบ.

Code Management and Execution

ModuleDescription
moduleจัดการการโหลดและการจัดการ modules.
vmให้ API สำหรับการคอมไพล์และรันโค้ดใน VM (Virtual Machine).
worker_threadsให้ฟังก์ชันการทำงานกับ threads.

Security and Cryptography

ModuleDescription
cryptoให้ฟังก์ชันการเข้ารหัสและการเข้ารหัสลับ.
tlsใช้สำหรับการสื่อสารเครือข่ายที่ปลอดภัยโดยใช้โปรโตคอล TLS/SSL.

Performance and Profiling

ModuleDescription
trace_eventsให้ API สำหรับการติดตามและการวิเคราะห์เหตุการณ์.
v8ให้ API สำหรับการโต้ตอบกับเครื่องยนต์ JavaScript V8.

TTY and Terminal

ModuleDescription
ttyให้คลาสสำหรับการทำงานกับ TTY (teletypewriter) devices.

High-Performance Data Handling

ModuleDescription
zlibให้ฟังก์ชันการบีบอัดและการคลายการบีบอัดข้อมูล.

Released under the MIT License