nodejs spawn set env variable 1

nodejs spawn set env variable

spawn( 'node', ['app.js'], { env: { ...process.env, NODE_ENV: 'test' } }})

Here is what the above code is Doing:
1. We’re using the spawn function from the child_process module to start a new Node process.
2. We’re passing in the path to the app.js file as the first argument.
3. We’re passing in an object as the second argument. This object contains the environment variables that we want to set for the new process.
4. We’re using the spread operator to copy all of the environment variables from the current process into the new process.
5. We’re setting the NODE_ENV environment variable to test.

Similar Posts