Flask vs node

Comparing flask vs node is a clice wich is formally nor correct because:

  • there is a python interpreter which is used to run applications built with flask web server frameworkd
  • There is a nodejs interpreter which is used to run an application built with express web server framework(or another one, when express is just most popular)

So both flask and express are web frameworks which main aim is:

  • Bind on some TCP or e.g. 8080 and wait for incoming connection
  • When some HTTP client connects to the port they just handle HTTP requests (which are basic text portions of data kinda GET /myurl/ ) by parsing all fields (METHOD, URL, HEADERS) then match URL to some high-level routing configuration (easy for developer) and execute so-called view functions
  • View-function again is easy to use for a developer-web framework can easily parse params from the route(e.g. get 1232 as separate function argument from URL /readpost/1232/) ad pass them to view as an additional arguments
  • Developer return some text-based or JSON-based object from view function when framework wraps it all into correct HTTP response and sends it back to TCP connection

Both flask and express are fult-featured great tools which can do this job.

What about differences:

Benefit of express and node - it is truly asynchronous

  • Nodejs world is truly asynchronous by default. You can run one tread of your express node process and it will handle thousands of requests per second because when one request started to be processed, some asynchronous operation (e.g. read to database) will release an event loop for handling the new connection
  • In python world flask is blocking (as well as Django), so if you will run a flask server in one process it will be limited to only one request at a time. If user runs a 3-seconds request which is waiting for a slow mail-send server, you will not able to handle another request those 3 seconds. The common solution-using some multi-process/multi-threading runner e.g. gunicor which will spawn threads and you will be handling several requests at a time (worthen then async CPU/memory resources usage of course). Or use aiohttp/fastapi which are async flask analogs. But coding on the libraries with async/await will require some skill(when a node does this asynchronously by defoult)
  • So when you try to make decision who is better flask vs node you can be sure that node will win in terms of efficiency.

Benefits of python flask-packages

Python PyPI has much more cool libraries than npm in nodejs world. Greatest example-automatic migration system. For flask you can use Alembic with SQLAlchemy ORM - you define models as classes, then run alembic and

it generates migrations that create tables in database for you. You rename field inside of model class, again run alembic command and it created migration which will be easily applied to your college computers or on the serve (Same and even better is only shipped in Django). It is hard to find something like this in the nodejs world.

If you don`t need relational (SQL) databases automatic migration is not your priority-probably you don`t need schema at all. But there area lot of cool libraries in the python world, so we tend to think that python development process will be faster and easier.

Who would win in fight flask vs node

From a business point of view in flask vs node battle, Flask, for sure, is more efficient in terms of spending time because to the good packages with good documentation. Faster and simpler development is also easier support. Though with true synchronicity you can use computing resources more efficiently, most of the projects will have a budget that will win much more from devel