简体   繁体   中英

node.js is it save to replace process.env object?

Say I have extend function that

extend(obj1, obj2) -> creates new object does not mutate sources

According to documentation process.env is just an object, but I wonder is it save operation to do the followng:

process.env = extend(process.env, {MY_SETTING: 'Something'})

so process.env will be completely replaced new object with the same properties?

It's probably safe, but there is no good reason to do it. env is defined in C++ code ( https://github.com/joyent/node/blob/v0.10.28-release/src/node.cc#L2324-L2332 ). As you can see accessing each property actually involves getenv invocation, which has O(n) complexity, so enumeration and copying of whole env object would be quite inefficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM