@@ -891,6 +891,10 @@ added: v0.5.9
891891The ` 'message' ` event is triggered when a child process uses [ ` process.send() ` ] [ ]
892892to send messages.
893893
894+ * Note* : The message goes through JSON serialization and parsing. The resulting
895+ message might not be the same as what is originally sent. See notes in
896+ [ the ` JSON.stringify() ` specification] [ `JSON.stringify` spec ] .
897+
894898### subprocess.channel
895899<!-- YAML
896900added: v7.1.0
@@ -1050,6 +1054,10 @@ be used to send messages to the child process. When the child process is a
10501054Node.js instance, these messages can be received via the
10511055[ ` process.on('message') ` ] [ ] event.
10521056
1057+ * Note* : The message goes through JSON serialization and parsing. The resulting
1058+ message might not be the same as what is originally sent. See notes in
1059+ [ the ` JSON.stringify() ` specification] [ `JSON.stringify` spec ] .
1060+
10531061For example, in the parent script:
10541062
10551063``` js
@@ -1060,6 +1068,7 @@ n.on('message', (m) => {
10601068 console .log (' PARENT got message:' , m);
10611069});
10621070
1071+ // Causes the child to print: CHILD got message: { hello: 'world' }
10631072n .send ({ hello: ' world' });
10641073```
10651074
@@ -1070,7 +1079,8 @@ process.on('message', (m) => {
10701079 console .log (' CHILD got message:' , m);
10711080});
10721081
1073- process .send ({ foo: ' bar' });
1082+ // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
1083+ process .send ({ foo: ' bar' , baz: NaN });
10741084```
10751085
10761086Child Node.js processes will have a [ ` process.send() ` ] [ ] method of their own that
@@ -1201,9 +1211,6 @@ It is also recommended that any `'message'` handlers in the child process
12011211verify that ` socket ` exists, as the connection may have been closed during the
12021212time it takes to send the connection to the child.
12031213
1204- * Note* : This function uses [ ` JSON.stringify() ` ] [ ] internally to serialize the
1205- ` message ` .
1206-
12071214### subprocess.stderr
12081215<!-- YAML
12091216added: v0.1.90
@@ -1319,6 +1326,7 @@ unavailable.
13191326[ `ChildProcess` ] : #child_process_child_process
13201327[ `Error` ] : errors.html#errors_class_error
13211328[ `EventEmitter` ] : events.html#events_class_eventemitter
1329+ [ `JSON.stringify` spec ] : https://tc39.github.io/ecma262/#sec-json.stringify
13221330[ `JSON.stringify()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
13231331[ `subprocess.connected` ] : #child_process_subprocess_connected
13241332[ `subprocess.disconnect()` ] : #child_process_subprocess_disconnect
0 commit comments