Passing variables from C++ to JavaScript (server-side to client-side)?

226 views
Skip to first unread message

Osman Zakir

unread,
May 12, 2018, 2:35:11 PM5/12/18
to v8-users
My issue is as stated in the title.  Is it possible to do this using V8?  If so, how?  Thanks in advance for any replies and/or help.  

Note: I have a Google API key and a currency API access key stored in environment variables I want to pass them to the client-side code.  The Google API key has to go the HTML page somehow and the other one to the JavaScript code.  

Anoop R. S.

unread,
May 12, 2018, 11:37:38 PM5/12/18
to v8-users
Hi,
Please see if this is of any help. I am not sure whether this is what you meant. 


regards,
Anoop R. S.

Osman Zakir

unread,
May 17, 2018, 8:39:28 PM5/17/18
to v8-users
Hi,

Thanks for the answer.  

I think this can help me.  I also need to know if I need to actually make a C++ addon for Node.js or if I just need to #include the v8.h header in C++ and require() v8 in JavaScript and then expose the variable from C++ to JavaScript that way without also making a Node.js addon (I'm using Browserify, so I can use require() client-side in my code).  

Anoop R. S.

unread,
May 18, 2018, 12:35:30 AM5/18/18
to v8-users
I don't have much idea about Node.js. I used v8 for embedding. 

regards,
Anoop R. S.

Isiah Meadows

unread,
May 18, 2018, 9:17:58 PM5/18/18
to v8-users
I would recommend that for questions specific to Node itself like this, you should check out https://github.com/nodejs/help first before asking here. There, they can help you with a wide variety of things, including things like this, and you're more likely to get better answers out of it. They can help you with both native addons and JavaScript-related questions, and they can help you with quite a few things.

Also, I thought I'd point out that for this particular case, if your server is in fact Node, I'd suggest using `process.env` instead (see https://nodejs.org/api/process.html#process_process_env). This does basically what you want, without much ceremony (and as a couple pros, it works across all platforms and it doesn't even require any C++ code).
Reply all
Reply to author
Forward
0 new messages