Skip to content

Commit fb13096

Browse files
committed
🎉 Initial Commit
0 parents  commit fb13096

27 files changed

Lines changed: 18336 additions & 0 deletions

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
#/*/node_modules
5+
# ignore all /node_modules subdirectories in this project
6+
**/node_modules
7+
/.pnp
8+
.pnp.js
9+
10+
# testing
11+
/coverage
12+
13+
# production
14+
/build
15+
16+
# misc
17+
.DS_Store
18+
.env.local
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Fullstack Project with React and Node.js
2+
========================================
3+
4+
This project is a **fullstack application** combining a **React frontend** and a **Node.js/Express backend** within a single project directory. This README will guide you through understanding the project structure, navigating the files, and running both applications together.
5+
6+
* * *
7+
8+
Project Structure
9+
-----------------
10+
11+
The project directory has two main subdirectories: `frontend` and `backend`. Each contains its own `package.json` file for managing dependencies and scripts, while a root-level `package.json` manages shared dependencies and scripts to make it easy to work with both applications from a single command.
12+
13+
### Directory Layout
14+
![Image showing the directory structure of a fullstack app project. The root directory, labeled 'fullstack-app,' contains two main folders: 'backend' and 'frontend,' along with a root-level package.json and README.md file. The backend folder includes a 'server.js' file for the Node.js server and its own package.json file. The frontend folder includes a 'src' folder for React components, a 'public' folder for static assets, and its own package.json file. This structure highlights the organization of frontend and backend code within a single project directory.](project-structure.png)
15+
16+
### Explanation of Each Part
17+
18+
* **backend/**: Contains all server-side code using Node.js and Express, including API routes, middleware, and backend-specific configurations.
19+
* **frontend/**: Contains all client-side code using React, including components, styles, and assets.
20+
* **Root `package.json`**: The root `package.json` defines shared dependencies (like `concurrently` for running both servers) and scripts for managing both frontend and backend projects from a single command.
21+
22+
### Version Control: Understanding `**/node_modules` in `.gitignore` and What is the `node_modules` Folder?
23+
24+
The `node_modules` folder is automatically created by **npm** (Node Package Manager) when you run `npm install`. It contains all the dependencies and sub-dependencies required for your project to function. Each project or workspace, such as `frontend` and `backend`, will have its own `node_modules` folder.
25+
26+
### What Does `**/node_modules` Do in `.gitignore`?
27+
28+
The `**/node_modules` entry in the `.gitignore` file tells Git to ignore all `node_modules` folders in the project, no matter where they are located. This is particularly important for a fullstack project where both the `frontend` and `backend` directories have their own `node_modules` folders.
29+
30+
* * *
31+
32+
Setting Up the Project
33+
----------------------
34+
35+
### Prerequisites
36+
37+
Ensure you have the following installed:
38+
39+
* **Node.js** (v14 or later)
40+
* **npm** (v7 or later for workspaces support)
41+
42+
### Installation
43+
44+
To set up the project, install all dependencies by running `npm install` from the root directory. This command will install dependencies for both `frontend` and `backend` automatically:
45+
46+
npm install
47+
48+
> **Note**: If you encounter errors with `npm install` in the root, try running `npm install` from the `frontend` and `backend` directories individually to install dependencies for each part separately.
49+
50+
* * *
51+
52+
Running the Project
53+
-------------------
54+
55+
The root `package.json` includes scripts to help you start both the frontend and backend servers simultaneously.
56+
57+
### Available Scripts
58+
59+
* **Install Dependencies**: Installs all dependencies in `frontend` and `backend` folders from the root.
60+
61+
npm install
62+
63+
* **Start Both Frontend and Backend**: Starts both the React app and the Node.js server concurrently.
64+
65+
npm start
66+
67+
* **React (Frontend)** runs on `http://localhost:3000`
68+
* **Express (Backend)** runs on `http://localhost:5000`
69+
* **Run Backend Only**:
70+
71+
npm run server
72+
73+
* **Run Frontend Only**:
74+
75+
npm run client
76+
77+
78+
* * *
79+
80+
How the Frontend and Backend Work Together
81+
------------------------------------------
82+
83+
* The **React frontend** makes HTTP requests to the **Express backend** to retrieve and display data.
84+
* The backend serves as an API and handles requests from the frontend, responding with JSON data.
85+
* **Example API Route**: In `backend/server.js`, there is a sample route:
86+
87+
```
88+
app.get('/api/project', (req, res) => {
89+
res.json({
90+
studentName: "Smith, John",
91+
projectName: "Weather App",
92+
projectUrl: "http://10.0.0.1:3000/",
93+
projectDescription: "Provides real-time weather updates for any location worldwide"
94+
});
95+
});
96+
```
97+
98+
* **Cross-Origin Resource Sharing (CORS)**: CORS is enabled to allow the frontend to access the backend API while running on different ports (`3000` for frontend and `5000` for backend).
99+
100+
* * *
101+
102+
Tips for Working with This Structure
103+
------------------------------------
104+
105+
1. **Navigating Between `frontend` and `backend`**:
106+
107+
* Use separate `package.json` files to add dependencies specific to each part of the project.
108+
* Run `npm install <package-name>` from within `frontend` or `backend` to install packages only for that directory.
109+
2. **Editing API Routes**:
110+
111+
* Add routes in `backend/server.js` as needed. You can create separate route files and import them into `server.js` for cleaner organization.
112+
3. **Frontend-Backend Communication**:
113+
114+
* In the frontend, use `fetch` or a library like `axios` to make requests to the backend API.
115+
* Example (in a React component):
116+
117+
```
118+
useEffect(() => {
119+
fetch('http://localhost:5000/api/project')
120+
.then(response => response.json())
121+
.then(data => setProjectData(data));
122+
}, []);
123+
```
124+
125+
4. **Environment Configuration**:
126+
127+
* Use environment variables in both `frontend` and `backend` for settings like API URLs, especially when deploying to production.
128+
129+
* * *
130+
131+
132+
133+
This structure allows you to manage the React frontend and Node.js backend independently while keeping everything organized within a single project. This setup makes it easy to develop and run a fullstack application while maintaining a clear separation between frontend and backend code.

backend/.dockerignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
node_modules
2+
npm-debug.log
3+
yarn-debug.log
4+
yarn-error.log
5+
.git
6+
.gitignore
7+
.env
8+
.env.*
9+
coverage
10+
*.log
11+
.DS_Store
12+
.vscode
13+
.idea
14+
test
15+
__tests__
16+
*.test.js
17+
*.spec.js
18+
README.md

0 commit comments

Comments
 (0)