What is React?

Install Node.js

To use React in production, you need npm which is included with Node.js.

What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to run JavaScript outside the browser. It is primarily used for server-side development, making it possible to create fast, scalable, and real-time applications.

Before Node.js, JavaScript could only run inside a web browser (like Chrome or Firefox). Node.js changed that by allowing JavaScript to run on a server, enabling backend development with JavaScript.

What is npm (Node Package Manager)?

npm (Node Package Manager) is the default package manager for Node.js. It helps developers install, manage, and share JavaScript libraries and tools easily.

Steps to Install Node.js:

Create a React App (Recommended: Using Vite)

React Project Structure (Vite + React)

src/ → This is the Core Folder for Your React Code:

main.jsx → Application Entry Point

This file renders your React app into the browser DOM. It connects the App component to the HTML file (index.html). Example:
ReactDOM.createRoot(document.getElementById('root')).render(
  <App />
)

App.jsx → Main Component of Your React App

This is the primary file where you write your React code. It serves as the root component of your application, and you can:

package.json → Project Configuration

React Image Import Methods

Method When to Use Example
Import (import logo from './logo.svg') When using images inside src/ <img src={logo} />
Direct Path (src="/logo.svg") When using images inside public/ <img src="/logo.svg" />
External URL For online images <img src="https://example.com/image.jpg" />

Check React Version Using npm

Execute this command in the terminal within your project directory:
	npm list react
	

Relationship Flow: React + Vite + Node.js

✍️ You write React code (components + JSX)
Vite builds and serves it (dev server + hot reload)
🟢 Node.js runs Vite (executes npm run dev)
🌐 Browser displays the app (renders the UI)

Hot reload: When you save your code, the browser updates instantly without refreshing the whole page.

React Comment Syntax Summary

Type Syntax Where to Use?
Single-line JavaScript comment // This is a comment Outside JSX
Multi-line JavaScript comment /* This is a comment */ Outside JSX
JSX Comment {/* This is a JSX comment */} Inside JSX

What is JSX? (JavaScript XML)

JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code inside JavaScript files. It is used in React to describe what the UI should look like.