首页 > 解决方案 > Nodejs Passing argument to fork object

问题描述

How to send "--max_old_space_size=1024" to child process fork? I tried to send this argument as args , argv Note that because I need communication channel, I could not use exec or spawn. So basically I want run my child process

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

as

node --max_old_space_size=1024 myfile.js

标签: node.jsmemoryargumentsfork

解决方案


You're looking for the execArgv property of fork's options:

require('child_process').fork('myfile.js', {
  execArgv: ['--max_old_space_size=1024']
});

Then in myfile.js you can check it's been considered through process.execArgv:

console.log(process.execArgv);

Which should output the same as if you directly call:

node --max_old_space_size=1024 myfile.js

This differentiates these 2 types of arguments: node <node's args> file.js <file's args>


推荐阅读