Cara menggunakan pipe to file nodejs

Panduan Referensi APIAWS SDK for JavaScript V3 menjelaskan secara rinci semua operasi API untukAWS SDK for JavaScript versi 3 (V3).

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Penggunaan modul kode oleh aplikasi web dalam skrip browser atau Node.js menciptakan dependensi. Modul kode ini dapat memiliki dependensi sendiri, menghasilkan kumpulan modul yang saling berhubungan yang dibutuhkan aplikasi Anda untuk berfungsi. Untuk mengelola dependensi, Anda dapat menggunakan bundler modul sepertiwebpack.

Parameterwebpackmodul bundler mem-parsing kode aplikasi Anda, mencari

npm install --save-dev path-browserify
0atau
npm install --save-dev path-browserify
1pernyataan, untuk membuat bundel yang berisi semua aset yang dibutuhkan aplikasi Anda. Hal ini agar aset dapat dengan mudah dilayani melalui halaman web. SDK untuk JavaScript dapat dimasukkan dalamwebpacksebagai salah satu dependensi untuk memasukkan dalam bundel output.

Untuk informasi lebih lanjut tentangwebpack, lihatpaketan moduldi GitHub.

Menginstal webpack

Untuk menginstalwebpackbundler modul, Anda harus terlebih dahulu memiliki npm, manajer paket Node.js, diinstal. Ketik perintah berikut untuk menginstalwebpackCLI dan JavaScript modul.

npm install --save-dev webpack

Untuk menggunakan

npm install --save-dev path-browserify
6modul untuk bekerja dengan file dan direktori path, yang diinstal secara otomatis dengan webpack, Anda mungkin perlu menginstal Node.js
npm install --save-dev path-browserify
7paket.

npm install --save-dev path-browserify

Mengonfigurasi webpack

Secara default, Webpack mencari file JavaScript bernama

npm install --save-dev path-browserify
8di direktori root proyek. File ini menentukan opsi konfigurasi Anda. Berikut ini adalah contoh
npm install --save-dev path-browserify
8file konfigurasi untuk WebPack versi 5.0.0 dan versi terbaru.

Persyaratan konfigurasi Webpack bervariasi tergantung pada versi Webpack yang Anda instal. Untuk informasi selengkapnya, lihatdokumentasi Webpack.

// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};

Dalam contoh ini,

// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
0ditentukan sebagaititik masuk. Parametertitik masukadalah filewebpackmenggunakan untuk mulai mencari modul impor. Nama file output ditentukan sebagai
// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
2. File output ini akan berisi semua JavaScript aplikasi perlu dijalankan. Jika kode yang ditentukan dalam impor entry point atau memerlukan modul lain, seperti SDK untuk JavaScript, kode yang dibundel tanpa perlu menentukan dalam konfigurasi.

Menjalankan webpack

Membangun aplikasi yang akan digunakanwebpack, tambahkan yang berikut ini ke

// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
4objek di
// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
5berkas.

"build": "webpack"

Berikut ini adalah contoh-contohnya

// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
5file yang menunjukkan menambahkanwebpack.

{
  "name": "aws-webpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-iam": "^3.32.0",
    "@aws-sdk/client-s3": "^3.32.0"
  },
  "devDependencies": {
    "webpack": "^5.0.0"
  }
}

Untuk membangun aplikasi Anda, masukkan perintah berikut.

npm run build

Parameterwebpackpackage modul kemudian menghasilkan file JavaScript yang Anda tentukan di direktori root proyek.

Menggunakan bundel webpack

Untuk menggunakan bundel dalam skrip browser, Anda dapat menggabungkan bundel menggunakan

// Import path for resolving file paths
var path = require("path");
module.exports = {
  // Specify the entry point for our app.
  entry: [path.join(__dirname, "browser.js")],
  // Specify the output file containing our bundled code.
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   // Enable WebPack to use the 'path' package.
   resolve:{
  fallback: { path: require.resolve("path-browserify")}
  }
  /**
  * In Webpack version v2.0.0 and earlier, you must tell 
  * webpack how to use "json-loader" to load 'json' files.
  * To do this Enter 'npm --save-dev install json-loader' at the 
  * command line to install the "json-loader' package, and include the 
  * following entry in your webpack.config.js.
  * module: {
    rules: [{test: /\.json$/, use: use: "json-loader"}]
  }
  **/
};
9

Paketan untuk Node.js

Anda dapat menggunakanwebpackuntuk menghasilkan bundel yang berjalan di Node.js dengan menentukan

"build": "webpack"
1sebagai target dalam konfigurasi.

target: "node"

Hal ini berguna ketika menjalankan aplikasi Node.js di lingkungan di mana ruang disk terbatas. Ini contohnya

npm install --save-dev path-browserify
8konfigurasi dengan Node.js ditentukan sebagai target output.

Untuk dapat menjalankan baris kode JavaScript Node.js membutuhkan sebuah engine Apakah nama dari engine tersebut?

Untuk mengeksekusi Javascript sebagai bahasa server diperlukan engine yang cepat dan mempunyai performansi yang bagus. Engine Javascript dari Google bernama* V8*-lah yang dipakai oleh Node.js yang juga merupakan engine yang dipakai oleh browser Google Chrome.

Apakah Node.js dalam menjalankan aplikasi ke web memerlukan web server atau bisa membuat webserver sendiri?

Untuk mendukung kemampuan tersebut, Node.js dibangun dengan engine Javascript V8 milik Google. Di samping itu, Node.js juga memiliki pustaka server sendiri sehingga Anda tidak perlu menggunakan program server web seperti Nginx dan Apache.

Node.js digunakan untuk apa?

Node.js adalah sebuah software yang digunakan untuk pengembangan aplikasi berbasis web dan ditulis dalam sintaks bahasa pemrograman JavaScript yang bersifat open-source dan cross platform. Jadi dengan Node.js, kita bisa menjalankan kode JavaScript di mana saja, tidak hanya terbatas pada lingkungan browser.