Home » Javascript » Passing variables between 2 javascript files in node.js express

Passing variables between 2 javascript files in node.js express

Posted by: admin June 30, 2018 Leave a comment

Questions:

I have a node express project with the files oriented like this (webstorm editor):

enter image description here

I would like to pass a variable from the marked index.js to app.js so that I can write that variable in data.json at the end.

I am still new to node.js and still confused about the client/server theory. It will be much easier if there is a way to write the data directly from index.js to data.json, or any other json file, but I think that this is not possible according to previous answers. Please correct me if I’m wrong.

Thanks!

Answers: