Categories
JavaScript Answers

How to run a Node.js script from within another Node.js script?

Spread the love

To run a Node.js script from within another Node.js script, we cal;l the fork method.

For instance, we write

require('child_process').fork('app.js'); 

to call fork to run app.js.

Then in app.js, we write

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

to add a console log.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *