Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How can I access Express req.local variables in another clientside javascript file

I want to access local variables from express and use them in other client side javascript files.

How would I retrieve this data?

1 Answer

Steven Parker
Steven Parker
243,656 Points

I haven't looked into the internals of Express, but any good JavaScript framework should be written to encapsulate its local variables. They should therefore not be accessible directly from other files.

I would expect first that whatever you may be trying to accomplish might be done through facilities provided by the framework API. If not, and it was absolutely necessary to get to some internal variables, you may need to modify the framework code to add accessor methods for the variables you need to use.