Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does React have a server on its own?

Tags:

First of all, I know the question is badly formulated. I can't think of any thing to describe the situation as I'm a beginner. So when on cmd we type npx create-react-app myapp, this sets up the react project. Then we could do npm start and we could view the react app on localhost:3000. I wish to know why it is so. The react app is on client side, so why does it need a server? Next, I want to set up a node js server and does it need to use the same port as the react app? My guts says no. Briefly, I wish to know why react use localhost:3000 when it is client-side. Thanks in advance

like image 504
Eye Patch Avatar asked Jan 31 '20 21:01

Eye Patch


1 Answers

Node is not required in order to use React. You do not need Node to run a React project. React is a client side UI library. What Node offers is a series of tools that allow you to be able to work with React more easily, such as Webpack (gathers code into a single bundle and listens for file changes to reload this bundle to show the updated code) and Babel (converts ES6 and JSX to plain JavaScript). npx itself is a Node tool which allows you to run a package, in this case with Create React App, which allows you to easily start a new React project. The server that you see is simply to allow for the reloading of the app in response to file changes in real time. The server is only for use in development.

like image 160
Jorge Navarro Avatar answered Sep 18 '22 11:09

Jorge Navarro