简体   繁体   English

node.js是否保存以替换process.env对象?

[英]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只是一个对象,但我想知道是保存操作来执行以下操作:

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

so process.env will be completely replaced new object with the same properties? 所以process.env会完全替换具有相同属性的新对象吗?

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 ). env在C ++代码中定义( 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. 正如您所看到的,访问每个属性实际上涉及具有O(n)复杂性的getenv调用,因此枚举和复制整个env对象将是非常低效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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