Can i store Objects in process.env

Short answer is: NO

No, you can't store objects in process.env because it stores environment variables like PATH, SHELL, TMPDIR and others, which are represented by String values. If you run command console.log(process.env); you can see all env variables of your system, in particular you can set your own env variables (e.g. process.env.home = 'home') which will be available during the process you run your nodejs application.

Solution exists!
Stringify JSON object and save as env variable. Then parse and use it when you need your object


process.env is to store your environmental variables not really to store your objects. You can store your variables like that:

process.env['CONSUMER_KEY'] = ""
process.env['CONSUMER_SECRET'] = ""
process.env['ACCESS_TOKEN_KEY'] = ""
process.env['ACCESS_TOKEN_SECRET'] = ""

Here is a link to it https://nodejs.org/api/process.html#process_process_env

If you want to store your methods you should create a global object and assign your methods to that one.


Altho you can't store objects in process.env directly, you can still store in process itself.

Tags:

Node.Js