1.

What is the fork in node JS?

Answer»

Fork() is used to spawn a NEW Node.js PROCESS. It invokes a specific MODULE with an IPC COMMUNICATION channel, thus enabling the sending of MESSAGES between a parent and child.

Example

const { fork } = require('child_process');

const forked = fork('child.js');

forked.on('message', (msg) => {
     console.log('Message from child', msg);
});

forked.send({ hello: 'world' });



Discussion

No Comment Found