How do I pass command line arguments to a Node.js program?

后端 未结 30 2658
梦如初夏
梦如初夏 2020-11-22 04:03

I have a web server written in Node.js and I would like to launch with a specific folder. I\'m not sure how to access arguments in JavaScript. I\'m running node like this:

30条回答
  •  无人及你
    2020-11-22 04:15

    Although Above answers are perfect, and someone has already suggested yargs, using the package is really easy. This is a nice package which makes passing arguments to command line really easy.

    npm i yargs
    const yargs = require("yargs");
    const argv = yargs.argv;
    console.log(argv);
    

    Please visit https://yargs.js.org/ for more info.

提交回复
热议问题