r/react • u/PMK_Phala • May 12 '24
Help Wanted Why is Node.js needed?
Hello, I'm learning React and on all the introduction videos I've watched none of them explain why node.js is installed. Can someone please explain to me why most beginner FE React tutorials require me to install node?
32
u/Right-Chocolate-5038 May 12 '24
Before node.js the browser (v8 engine) was the only environment javascript could run in, meaning client side only.
With node.js you can run javascript code in the terminal, outside the browser (server side).
0
May 12 '24
[deleted]
4
May 12 '24
And to expand on this response, this is what makes the cli command to initialize a new react app possible, pulling packages from the npm repository (Node Package Manager) like the now-deprecated create-react-app repository or vite, etc.
11
u/Krytom May 12 '24
Installing the package manager (npm) is probably one of the main reasons.
1
u/cimmic May 12 '24
Actually, true. Almost all my JS projects are 100% client side but npm is all over my terminal.
8
5
u/_nathata Hook Based May 12 '24
Node is necessary for dependency management (npm and related) and build and dev server
17
u/Lumpy_Pin_4679 May 12 '24
I’m curious about something - is Google not a thing anymore? This is something that can easily be searched. Is the preference just to have some random person, who might not have a clue what they’re saying, explain it to you? Why not just search and learn?
8
u/AlliedSnail May 12 '24
Google is useful because of questions like this. And duplicate questions help generate a wealth of information that enriched the topic further. Most people reading here probably learned something new that they never would have googled themselves
-3
u/Lumpy_Pin_4679 May 13 '24
Uhhhh ok? This wasn’t posted for any of those reasons and none of that answers my question so not sure what your point is.
3
u/AlliedSnail May 15 '24
I Googled ‘why is node js needed Reddit’ and this discussion is in the top five results. Do you understand now?
2
u/yeonw May 13 '24
Why you have to be so mean ? Isn't this groups for discussions? If a newbie as a doubt we are supposed to help. With this attitude I don't think it will take you anywhere.
2
1
u/LikeWhattttlol May 13 '24
I cant get npm run dev to work can someone help me
1
1
May 13 '24
1.open your package.json file 2.under scripts, search for something like "dev":"node filename.js"
3.if it don't exist add this line "dev":"node filename.js"
you can replace dev with any other name
now head to terminal and type:
npm run dev or npm run (put here the other name you just wrote inplace of dev for example say it "start" , so your final command will be npm run start)
1
1
1
u/TheRNGuy May 16 '24
So you can use JSX, database, fullstack frameworks like Remix, and other stuff that require server.
28
u/EmployeeFinal Hook Based May 12 '24
You technically can run your code directly in the browser. But modern development has a lot of tools to help, and these tools needs to prepare and build the code for browsers. Node is the most popular runtime to run these tools.