javascript - process.env.VARIABLE going to undefined after assigning string -


i running tests mocha , node in windows, , env variables showing weird behavior. code below

var stringmock = json.stringify(mock); process.env.mocks = stringmock; if(stringmock !== process.env.mocks) {     console.log('typeof stringmock: ', typeof stringmock);     console.log('typeof process.env.mocks: ', typeof process.env.mocks); } 

it's weird if statement evaluates true, result of log is:

    typeof stringmock: string     typeof process.env.mocks: undefined 

how can possible? , if ran code in codeship linux, doesn't happen, can node bug windows.

i suspect node has kind of limitation size of string env variables, couldn't find useful it.

the real questions are:

  1. what value of mock?
  2. what value of stringmock?
  3. what value of process.env.mocks?

having types part of data.

i can imagine 1 value mock make stringmock !== process.env.mocks evaluate true, , undefined. that's because json.stringify() return undefined instead of string, , thet undefined stringified when saved in environment variables.

but strangely enough, output program:

var mock = undefined;  var stringmock = json.stringify(mock); process.env.mocks = stringmock; if(stringmock !== process.env.mocks) {     console.log('typeof stringmock: ', typeof stringmock);     console.log('typeof process.env.mocks: ', typeof process.env.mocks); } 

is quite opposite of you're getting:

typeof stringmock:  undefined typeof process.env.mocks:  string 

that's because first 1 in undefined value , second 1 string "undefined". here have opposite of that, quite strange , quite frankly unable reproduce result value have tried, nan, infinity, 0, '', etc. else serialized json should either return string (which same in env var) or throw exception (for example circular references).

the hint comes mind hitting length limit of operating system - trying save long string resulting in not saving string @ environment.

and when thought searched , seems there's limit of 32k characters on windows, see:

the theoretical maximum length of environment variable around 32,760 characters. however, unlikely attain theoretical maximum in practice.

try printing stringmock.length , may answer question.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -