Why is node.js even an option in web3? Web3 development from bird eye's view

Hello

After I read this post:

I am struggling to understand why we need Node.js in web3 development. In the Ethereum dApp programming course, we put all the logic such as communicating to blockchain, in the frontend (normal javascript). And everything worked fine.
So I thought why is there a need for backend (server side programming) in web3 development. Of course, when we do big historical queries with filters or real time alerts, we use services like Moralis or Infura for the computing power and full node access but that is just used for queries.

I may not be understanding the “full picture” of web3 development.
Can someone help me understand this?

@kenn.eth

1 Like

Hey @REGO350, hope you are well.

I think your are not understanding the whole picture for a dapp, the frontend depends on a backend one way or another, there should be a server that should manage the packages to expose the frontend as a website (www.mydapp.com for example).

That way, there is always a need for a backend infrastrucure (vps or physicals servers, or moralis).

Web3 JS is a node package, while nodeJs is the environment to deploy and manage those packages to be able use it in the front end, but you can also use their CDN (which is basically a server that your website will connect to get all the web3js code functionality).

Another trick is just to get the url of the CDN, open it on a browser window and copy the entire code that is show, save that code into a JS file with some name like “myWeb3.js” and you now basically have your own web3 module.

But the entire picture is that at the end, the frontend by itself does not do a dapp, you need a backend infrastructure to execute the frontend instructions.

hope this helps.
Carlos Z

1 Like

Thank you for the detailed reply.

I think this topic is not only for web3 but web development in general.
So basically, the backend is there to host the frontend and configure node packages to use them at frontend. When a user visits www.mydapp.com, the backend job is to send the website data (such as HTML, CSS, and JS).

Am I correct?

I think my next task is to learn about the backend and combine the two stacks.

Yeah thats correct. When you use web3 in nodeJs you just import it in each page you need it like

import { web3 } from "/node_modules/web3"

But that just in case you need to use web3 functionalities in backend side.

1 Like

Here is another source that might help web3 developer