2

Like here

npm install -g create-react-app
create-react-app my-app

cd my-app
npm start

Why do we use npm and node . Why can't we use just a single cdn file ?

Vivek Iyer
  • 154
  • 1
  • 6
  • 16
  • 1
    Because npm includes a lot of things that browsers don;t support currently. Like Webpack support which bundles the modules allows you to write modular code without worrying about browser support etc. It gives you live reload, Linters too. – bugwheels94 Jul 15 '17 at 06:26

3 Answers3

8

ReactJS uses Node.js, a JavaScript runtime, to build your JavaScript code.

Basically, the ReactJS is a JavaScript framework which needs the help of node js and npm(Package manager) to tell the native side(Android/iOS) that these are packages I need to run my app. And it adds all the dependencies needed to run the app.

MD Aslam Ansari
  • 1,565
  • 11
  • 19
3

You can just use a simple html/cdn setup. The problem comes when you start having to manage a lot of dependencies, which inevitably happens. You'll eventually want to divide your project among several files to help organize it. All this becomes difficult without tools like NPM,Webpack, etc. This is especially true if you are working in a group where you want to communicate to strangers what is needed to build you program.

If you're just learning React or building a quick, small project the CND is fine, but eventually you'll need a more robust way to deal with this and npm works well.

Mark
  • 90,562
  • 7
  • 108
  • 148
0

Nodejs is not compulsorily required to run react code or build react apps. It is required to use so many tools that makes react development easy and avoid doing things manually. For example - Tool chain create-react-app is a npm package(which in turn require nodejs to be installed on system) which setup development environment and makes so many things already configured.