Full stack web app : python and javascript

so I thought I’d create a post because whilst Codecademy has been phenomenal for getting me to understand different language concepts and ideas I’m still struggling with how the ‘connection bit’ happens between a python script and the front end in javascript.

Lets say I’ve written a really cool python script to do some NTLK based natural language processing. After receiving text input from the user, I want to return results based on what my python script has ran (the string they entered being the input).

I still, frankly, don’t know fully how this operates. How do I connect the javascript form input to the python script, inside a react app.

  1. Am I forced to use a python back-end like Flask or Django for this ?
  2. What are the best resources and materials or parts of the courses on code-academy for helping
  3. is there any other resources, YouTube specific content for example, that I can check to help me wrestle with this idea better.

Thanks in advance for all responses.


For the CodeAcademy crew: I would just like to give a strong second to this question. Understanding the high level view of “What pieces are required” and “How are they supposed to fit together” is one of my main questions right now. Basically, what are the tools/technologies needed to build a fully functioning web app, and what do I need to make sure I can do with them?

There’s a couple of ways I can think of doing this.

The first is to use the Node child_process API which you can use to spawn another process. In your example where you have a JS-based front-end, this could be used to spawn the Python interpreter as a subprocess.

That would allow you to invoke the Python program (by being able to call python my_program.py arg1 arg2...), assuming that it accepts command-line arguments as input.

There’s a simple example of doing this here, on Medium

The other way, which you’ve already considered, is to use something like the Flask framework to create an API to your Python back-end. That would allow you to exchange data between the JS front-end and the Python back-end as JSON.

There’s an example of JS-Python data exchange using JSON here.

Hope that helps. :slight_smile:

Not sure if this helps you @truematthewkirkham, but it kind of helps me. But I do need to ask a more general question: basically is the real need to find a full-stack that let’s you connect the front-end with the back-end? For example, if you are using PostgreSQL, maybe using the PERN stack to take what you have in the back-end and utilize it on the front end? Because I think that’s what’s needed, just not sure, but if it is there are many different stacks to do it with, just depending on what you are most comfortable using/learning and what is best suited to what you’re trying to do.

1 Like