nodejs | 명령 행 인 자 를 가 져 오고 cli 스 크 립 트 에 인 자 를 전달 합 니 다.

791 단어 node
import { createInterface } from 'readline'

export const getUserInput = (question: string): Promise =>
    new Promise(resolve => {
      const terminal = createInterface({
        input: process.stdin,
        output: process.stdout
      })
      terminal.question(question, answer => {
        terminal.close()
        resolve(answer.trim())
      })
    })

// getUserInput('input: ').then(res => console.log(res))

 node ./index.js param    스 크 립 트 에서 param 가 져 오기
process.argv // string[]

최근 에 ts 로 cli 도 구 를 썼 습 니 다. 관심 있 는 것 은 시도 해 보 세 요.
npm install saber-tsmod -g

cli 프로그램 소스 코드:
Saber2pr/saber-tsmod
https://github.com/Saber2pr/saber-tsmod

좋은 웹페이지 즐겨찾기