It isn't possible to modify the env vars of a running process. This isn't unique to NodeJS processes. It's just how env vars work on UNIX like operating systems. The vars live within the address space of the process. And while they are, typically, initially placed at a well known location near the top of the stack the current vars are likely to be at an arbitrary address in the heap. Env vars are intentionally private to each process. So unless the program provides an API for changing its env vars you can't modify them once the program is running.
Here is what the above code is Doing:
1. It’s creating a child process.
2. It’s setting the env vars of the child process.
3. It’s running the child process.
4. It’s waiting for the child process to exit.
5. It’s printing the exit code of the child process.