Skip to content
youhoc
  • Pages
    • Home
    • Modern App Guidelines
    • Linux
      • Day 1: Linux Distributions & Navigation
      • Day 2: User Management
      • Day 3: File Permission & Ownership
      • Day 4: Package Management
      • Day 5: Services Management
    • Javascript
      • JS The Weird Part
        • Execution Context
        • Types & Operators
        • Objects & Functions
        • Error Handling & Strict Mode
        • Typescript, ES6, Tra
      • Modern JS
        • JS in the Browser
        • Data Storage JSON
        • Modern JS
        • Advanced Objects & Methods
        • Webpack & Babel
        • Async
      • jQuery
        • In-depth Analysis of jQuery
      • React-ready JS
        • Arrow Function
        • Template Literals
        • Logical AND, OR, Ternary, Nullish Operators
        • Destructuring & Rest Operator
        • Array Method
        • Immutability and Spread Operator
        • Promises, Async/Await, Callback
    • PHP
      • gruntJS
      • composer
      • MySQL
    • Docker
      • Container Basics
      • Container Networking
      • Container Image
      • Container Volume & Persistent Data
      • Dockerfile
      • Docker Compose
      • Docker Registry
    • Node.js
      • Installing & Exploring
      • Loading Modules
      • icon picker
        npm - Get Command Input
      • Web Server
        • Express Web Server
      • Template Engine & MVC
      • File System & Input Arguments
      • 6. Deploy to Heroku & Github
      • Authentication
      • 7. Databases
      • 8. Rest API
      • Errors
    • ReactJS
      • React from Andrew
        • Summary from Next
        • 1. Basics
        • 2. React Components
        • 3. Webpack
        • 4. Styling with SCSS
        • 5. React Router
        • 6. React Hook
      • Modern React From The Beginning
        • Intro to JSX
        • Vite Build Tools
        • Basic Component Creation
        • Component State
        • Props & Component Composition
        • useState with Inputs & Form Submission
        • useEffect, useRef & Local Storage
        • Async / Await and Http Request in React
        • React Router: Declarative Mode
        • ContextAPI
        • React Router: Framework Mode
          • File-routing & HTML Layouts
          • Server-side Data Query
          • Links & Navigation
          • Loaders
    • Typescript
      • Type User vs UserProp
    • Payload CMS

npm - Get Command Input

npm arguments

Truyền biến vào JS bằng cách thêm các giá trị phía sau hàm thực thi
Kiểm tra biến truyền vào bằng cách chạy process.argv (argument variables). process.argv là một mảng chứa 3 thứ:
đường dẫn đến node
đường dẫn đến file thực thi app.js
các biến khác
Dùng package Yargs để xử lý các biến truyền vào app
Cài đặt
Require
Chạy thử với argv
Hiển thị ra
Biến đặt đầu tiên yargs hiểu là command
Các tham chiếu có dấu -- tự tách ra thành mảng, được hiểu là biến để command xử lý

yargs xử lý các tham số truyền vào app.js như câu lệnh và biến.
command : câu lệnh đầu tiên
builder : các tham số truyền vào
Chúng ta chỉ cần viết hàm để xử lý. Khai báo hàm như sau:
Commands:
Xử lý các command và builder bằng câu lệnh chạy hàm

npm script

create a new node project
create a custom script for Node project

Install 3rd party packages

local OR global package?

local: only use in THIS project
global: use anywhere in this machine or server

dev OR production?

development dependencies: only use for dev, no need in production
dependencies: must have packages for running in production

Global Modules vs Core Modules vs 3rd-party Modules

Global features: Keywords like const or module.exports function or some global objects like process
No need to import or install, just USE
Core Node.js Modules: Examples would be the file-system module ("fs"), the path module ("path") or the Http module ("http")
Need to IMPORT, but NO INSTALL
Third-party Modules: Installed via npm install - you can add any kind of feature to your app via this way
INSTALL and IMPORT for use
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.