How do I run a Node.js script from within another Node.js script

后端 未结 3 584
北荒
北荒 2020-12-04 23:25

I have a standalone Node script called compile.js. It is sitting inside the main folder of a small Express app.

Sometimes I will run the compile.j

3条回答
  •  孤街浪徒
    2020-12-04 23:54

    Put this line in anywhere of the Node application.

    require('child_process').fork('some_code.js'); //change the path depending on where the file is.
    

    In some_code.js file

    console.log('calling form parent process');
    

提交回复
热议问题