← Back to React Course | Chapter 1: Environment Setup & Tooling | Lesson 2 of 10

Node.js और npm Install करना

Node.js और npm वह toolbox और hardware store हैं जो React से कुछ भी बनाना शुरू करने से पहले आपको चाहिए।

React को Node.js की ज़रूरत क्यों है

React खुद बस एक JavaScript library है, लेकिन एक असली React project बनाने के लिए tools (bundlers, compilers) चाहिए जो आपके computer पर run हों इससे पहले कि app कभी एक browser तक पहुंचे।

Node.js वह JavaScript runtime है जो उन build tools को browser के बाहर run करता है।

Note: सबसे stable experience के लिए nodejs.org से Node.js का LTS (Long-Term Support) version download करें।
Warning: एक पुराना Node.js version modern build tools run करने में fail हो सकता है -- एक नया project शुरू करने से पहले node -v से अपना version check करें।

उदाहरण: Why React Needs Node.js

markup
<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
  <div id="root"></div>
  <script type="text/babel">
function BuildStepDemo() {
  const jsxSource = 'function Hi() { return <p>Hi</p>; }';
  const compiled = Babel.transform(jsxSource, { presets: ['react'] }).code;
  return (
    <div>
      <p>Your source: <code>{jsxSource}</code></p>
      <p>What a build tool (via Node.js) turns it into:</p>
      <pre>{compiled}</pre>
    </div>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<BuildStepDemo />);
  </script>
</body>
</html>

उदाहरण: Installing Node.js

bash
# Windows (winget)
winget install OpenJS.NodeJS.LTS

# Mac (Homebrew)
brew install node

# Linux (Debian/Ubuntu, apt)
sudo apt update
sudo apt install nodejs npm

# verify the install
node -v
npm -v

⚠️ Run this in your own terminal or Node.js environment.

npm क्या Install करता है

npm (Node Package Manager) Node.js के साथ ship होता है और आपके project की dependencies, जैसे react और react-dom, को आपकी package.json file के आधार पर एक local node_modules folder में download करता है।

Note: किसी भी existing project को clone करने के बाद एक बार npm install run करें ताकि यह जिस पर depend करता है वह सब download हो जाए।
Warning: node_modules folder को git में commit करना repository को bloat करता है -- यह हमेशा .gitignore में होना चाहिए और npm install से regenerate किया जाना चाहिए।

उदाहरण: Running npm install

bash
$ npm install
npm WARN deprecated ...
added 1420 packages in 12s

# reads package.json and downloads everything it depends on into node_modules/

⚠️ Run this in your own terminal or Node.js environment.

package.json File

package.json आपके project का नाम, इसकी dependencies (जैसे react), और जो scripts आप run कर सकते हैं (जैसे npm start) list करता है। यह वह file है जो npm पढ़ता है यह जानने के लिए कि क्या install करना है।

Note: किसी भी React project में package.json खोलकर exactly देखें कि यह किन library versions पर depend करता है।
Warning: reinstall किए बिना package.json में version numbers को manually edit करना node_modules को out of sync छोड़ सकता है जो list किया गया है उससे।

उदाहरण: The package.json File

bash
$ cat package.json
{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build",
    "test": "vitest"
  }
}

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक बहुत पुराना Node.js version install करना जो modern React tooling के साथ incompatible है।
  2. एक project शुरू करने से पहले node -v और npm -v से installation verify न करना।
  3. Global npm installs को project-local dependencies के साथ confuse करना।
चैप्टर सारांश
  • Node.js वह JavaScript runtime है जो React के build tools को power करता है।
  • npm (Node Package Manager) project dependencies install और manage करता है।
  • दोनों nodejs.org से एक साथ install होते हैं।
  • एक terminal में node -v और npm -v से installation verify करें।
ब्राउज़र सपोर्ट

Applicable नहीं -- Node.js और npm development-time tools हैं, browser में run होने वाली कोई चीज़ नहीं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.