Private: ReactJS for Beginners
    About Lesson

    This tutorial will guide you through the process, covering the installation of Node.js and npm, setting up a React project using Create React App, and an overview of the project structure.

     

    Installing Node.js and npm

    Node.js is a JavaScript runtime that allows you to run JavaScript on the server side. npm (Node Package Manager) is a package manager for JavaScript, which comes bundled with Node.js. It allows you to install and manage third-party libraries and packages.

    Installing Node.js and npm

    Download Node.js:

    Visit the official Node.js website: https://nodejs.org/.

    Download the LTS (Long Term Support) version for your operating system.

    Install Node.js:

    Run the installer and follow the instructions.

    Ensure that the installer includes npm (it is included by default).

    Verify Installation:

    Open your terminal or command prompt.

    Check the installed versions by running: 

    node -v
    npm -v

    You should see the version numbers for Node.js and npm, indicating successful installation.

     

    Setting up a React Project using Create React App

    Create React App is an officially supported way to create single-page React applications. It offers a modern build setup with no configuration.

    Setting up a React Project

    Open Terminal or Command Prompt:

    Navigate to the directory where you want to create your React project.

    Create a New React Project:

    Run the following command:

    npx create-react-app my-app

    Replace my-app with your desired project name.

    npx is a package runner tool that comes with npm 5.2+ and higher. It allows you to run Create React App without globally installing it.

    Navigate to Your Project Directory:

    cd my-app

    Start the Development Server:

    Run the following command to start the development server:

    npm start

    This command starts the development server and opens your new React app in your default web browser.

    You should see a page with the React logo and some boilerplate content.

     

    Overview of Project Structure

    Once your React project is set up, you’ll see a directory structure like this:

    my-app/
    ├── node_modules/
    ├── public/
    │ ├── favicon.ico
    │ ├── index.html
    │ ├── logo192.png
    │ ├── logo512.png
    │ ├── manifest.json
    │ └── robots.txt
    ├── src/
    │ ├── App.css
    │ ├── App.js
    │ ├── App.test.js
    │ ├── index.css
    │ ├── index.js
    │ ├── logo.svg
    │ ├── reportWebVitals.js
    │ └── setupTests.js
    ├── .gitignore
    ├── package.json
    ├── README.md
    └── yarn.lock

     

    Key Directories and Files

    node_modules/: Contains all the dependencies and packages installed via npm.

    public/: Contains static files like index.html, which serve as the entry point for the web application, and other assets like images and icons.

    src/: Contains the source code for your React application.

    • App.js: The main component of your application.
    • index.js: The JavaScript entry point where React is rendered to the DOM.
    • App.css and index.css: CSS files for styling your application.
    • App.test.js: Test file for App.js.
    • reportWebVitals.js: Used for measuring performance in your application.
    • setupTests.js: Configures the testing environment.

    package.json: Contains metadata about your project and lists dependencies.

    README.md: A markdown file with information about your project.

    .gitignore: Specifies which files and directories should be ignored by Git.

    yarn.lock: Used if you are managing dependencies with Yarn instead of npm.