Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS vs NodeJS - Why do I need to create both?

I understand that React is frontend, and NodeJS is the backend that allows Javascript code to function outside of a browser. What I don't understand (and this is after following tutorials online on setting up a React project and a NodeJS project) is why I have to create an instance of each.

For example, in my React project, I managed to create a website. But because I needed a backend, I decided to use NodeJS. But I'm doing NodeJS tutorials, and I can create a website using NodeJS too. I'm confused because right now, it's appearing to be that React and NodeJS do the SAME THING.

I have never worked with NodeJS before so I am a bit confused. I was under the impression that I would just use NodeJS to host the backend, but after seeing that I'm literally having to create an entire website with NodeJS, I don't understand how I'm supposed to use React and NodeJS together.

How do the two, React and NodeJS, integrate together to create a fully-functioning web app? I have yet to see something online that clearly breaks down how the two interact.

like image 572
McFloofenbork Avatar asked May 30 '19 17:05

McFloofenbork


People also ask

Do I need to use node JS With React?

You don't need Node to run a React project. You don't even need a browser. React gives you a language to describe a user interface (UI). That interface could be the controls in your car, a modern fridge screen, or your microwave buttons.

Why use react JS and node JS?

Node. js enables the creation of scalable and quick back-end RESTful APIs. On the other hand, React is a front-end library that creates interactive user interfaces. With both tools, you can fast build complex and scalable web apps.

Can you use React and Nodejs together?

Yes, definitely, and in fact, Nodejs is the most convenient platform for hosting as well as running a web server for a React application. It's because of two main reasons: Using an NPM (Node Package Manager), Node works alongside the NPM registry to easily install any package through the NPM CLI.

Why do we need node JS install for React?

The main reason, as pointed out in the article, is: Easy package management. This means you can upgrade the package easily later on. JSX is the templating language that makes it way easier to write components: <h1>Hello Word</h1> reads so much better than React.


2 Answers

React is front-end library. It provides great tooling for creatiing user interfaces. And it creates a single page application. Which means when you open a react app. It does not reload and its really fast.

While you could also use nodejs and something like handlebars to create a website. But that website would be rendered on server and then served to the user. But its alot more than that. There are a lot of things that you want to do on the server. Like authentication. You want that part to be secure. So you keep it on the server.

Now the answer to the final part of your question.

For a fully functional app. You would use react to create user interfaces. And nodejs for creating an API which your react app will call.

like image 74
Muhammad Kamran Avatar answered Sep 17 '22 13:09

Muhammad Kamran


NodeJS is not just regular javascript, it is a javascript runtime that sits on top of a C++ engine called V8, provided by Google. Node executes outside the browser, whereas React / Vue / Angular / etc are in-browser javascript frameworks.

React is a whole separate animal; it is a framework that renders its own DOM in the browser. It is a javascript engine that is configured to optimize DOM manipulation.

While the development pattern of frontend and backend appear similar, they are doing different things. React is handling component lifecycles, applying dynamic style rules, processing in-browser data, and making API calls. Node is handling requests from the browser, coordinating access to the server's file system, managing network I-O, performing cryptographic evaluation, etc. Because of these different responsibilities, Node makes use of different dependencies (read: node modules) than a frontend framework.

Ultimately, Node and React communicate through HTTP calls (or, less frequently, through a WebSocket or SOAP protocol).

It would behoove you to read about how node works under the hood.

like image 24
Len Joseph Avatar answered Sep 18 '22 13:09

Len Joseph