Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 249 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can i store Objects in process.env

#1
I'm storing an object (which has several methods) into `process.env` as below:

var obj = createObject(); // returns new object
process.env.OBJ = obj;

When I access this object from other places like below, I don't see any of the methods.

var obj = process.env.OBJ;

Showing `[Object Object]`.

Why is that?
Reply

#2
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

[To see links please register here]


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

#3
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
Reply

#4
Altho you can't store objects in `process.env` directly, you can still store in `process` itself.
Reply

#5
Try to stringify the object and pass into the process.env and parse the string to get the object this will work.
Eg.

var obj = createObject(); // returns new object

process.env.OBJ = JSON.stringify(obj);

Use this in code like `let objFromEnv= JSON.parse(process.env.OBJ);`



Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through