How to execute 'npm run' command programmatically?

前端 未结 3 1544
日久生厌
日久生厌 2021-02-05 02:08

I have some custom testing script, which I can run with npm run test command, which executes some Node script for starting e2e/unit tests. But before it I must star

3条回答
  •  耶瑟儿~
    2021-02-05 02:54

    Just install npm:

    npm install npm
    

    Then in your program:

    npm.commands.run('dev', (err) => { ... });
    

    See the source for more info. The npm.command object is an unofficial API for npm. Note that using exec or spawn to execute npm is safer, since the API is unofficial.

提交回复
热议问题