S
S
sajtim2021-11-30 16:40:54
JavaScript
sajtim, 2021-11-30 16:40:54

Why do we need nodejs if there is fetch?

Hello everyone.
Despite the large amount of literature from the Internet, I just can’t grasp the basic concept of organizing the work of a website (application). Or at least generally accepted. Therefore, I can’t start studying the backend, although I decided for myself a long time ago that it would be only javascript with its ecosystem.
One of the main unresolved issues is the organization of open and closed parts of the application. Now I organized my site axdrv.ru , and still ran into the same question. For example, now the list of articles is organized through the fetch method, which pulls up the json file that is located directly in the folder with the site, and therefore access to it is easily opened through the debugger:
61a624324d879872685459.png
61a624e2462f6573419089.png
Obviously, when the issue concerns privacy, this approach is unacceptable.
Then we can assume that let the json files be stored somewhere on the side, and access to them is limited by the CORS policy. However, the same fetch suffices again, why nodejs? Is it just to make development easier with it?
And, the second question after. I understand since nodejs technology is so popular, I will get an answer pretty soon why it is worth using it, but on the Internet I still find the same pattern, like: React or Vue" But, as for me, nodejs is primarily a server-side framework, why not use it as a request-response helper, and do the rendering the old fashioned way, or almost, like statically dynamic html? And, where to install it then, in the internal file structure or access it from the outside?
Options:
a) all in one folder;
b) the client separately, nodejs and the database together, separately from the client;
c) the client and nodejs together, the database is separate, nodejs only serves but does not render to the client;
d) client separately, nodejs separately, database separately.
The site uses Web Components, in general, everything is done manually, more for a complete understanding of what is where and why.
Thanks in advance.
P.S. Most of all I'm stuck on the action attribute of the form tag<form action="">
If I write the path to the handler in nodejs, then I have not yet found how the handler can give the command to render the page that is on the client side. Everywhere it is described how to get the corresponding page from the server. And I have all the templates on the client, only the data is needed. So, is it better to use onsubmit preventDefault and handle the fetch request in a javascript file? There is a big gap somewhere.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sajtim, 2021-12-01
@sajtim

It turned out that the topic is not so obvious, and there is no standard solution, both for the first and for the second questions. There are many options, the Internet does not stand still, so we solve the issue on an individual basis.
Who, suddenly, came in search of a solution, I can suggest looking for the security of the client-server site on the first question, the file structure of nodejs on the second.
Please do not blame for the holivar topic.
Thanks to everyone for the replies and comments.

L
Leonid, 2021-11-30
@caballero

nodejs is a backend, that is, the
fetch web server performs ajax requests to the server, it doesn’t care if the node is there or not
, these things are not connected in any way.
As for the second question
, the client, the node as a web server and the database, again, are different things that perform different functions, the concept together or separately does not make sense

T
true, 2021-11-30
@RAFAILgaley

it is better to start with php
and if it is not enough, then use nodejs
nodejs is needed, for example, for a server that, while executing a bunch of client requests, still does complex calculations in parallel, for example, for a multiplayer game,
start with a simple server on which a simple api that writes to files reads and gives json
without anything, without frameworks and ready-made subds,
just to understand the client-server architecture and how to work with data
and to protect files on the server, set up the htaccess file , I
’ll tell you more, ask

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question