Run function in script from command line (Node JS)

前端 未结 11 474
情书的邮戳
情书的邮戳 2020-12-07 07:25

I\'m writing a web app in Node. If I\'ve got some JS file db.js with a function init in it how could I call that function from the command line?

11条回答
  •  攒了一身酷
    2020-12-07 07:59

    Try make-runnable.

    In db.js, add require('make-runnable'); to the end.

    Now you can do:

    node db.js init
    

    Any further args would get passed to the init method.

提交回复
热议问题