0

I'm making a simple socket.io game and I need client/client.js to be able to use variables and funtions from index.js You can check the project out here: https://repl.it/@Helixable/Sword-Arena-v10 Please help me. I'm new to javascript and this is like coder's block for me. How can I fix this without using the alert method?

  • Possible duplicate of [Can I access variables from another file?](https://stackoverflow.com/questions/3244361/can-i-access-variables-from-another-file) – Steven B. Mar 04 '19 at 19:03
  • Which functions specifically? Because in your Node architecture client.js shouldn't need to touch your main app i.e. index.js. – Mr Rethman Mar 04 '19 at 19:12
  • 1
    You seem to be mixing client and server side code. You won't be able to share variables directly between these files because they most likely will run in completely different environments. – djfdev Mar 04 '19 at 19:13
  • @djfdev is spot on! If you're needing to reuse common or util type functionality between client and server-side you should extract it into another file and import/require into the various instances. – Mr Rethman Mar 04 '19 at 19:23

1 Answers1

1

On this site and on the web there are several entries that answer your question, making a simple search you should find them, I leave a couple of results.

Can I access variables from another file?

Can we call the function written in one JavaScript in another JS file?

Do not forget before asking to spend a few minutes searching if there are any similar questions.

devin
  • 28
  • 1
  • 5