Skip to content

kushal1061/eDukaan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This web app is a full-stack application built with React for the frontend, Node.js with Express for the backend, and MongoDB as the database.

/kirana 2.0 /backend - index.js # Entry point for the backend - /models # MongoDB Models - /routes # Express routes - /controllers # Request handlers - /middleware # Custom middleware - package.json # Backend dependencies and scripts /frontend - /src # React components and assets - /public # Static files - package.json # Frontend dependencies and scripts

Prerequisites Before getting started, make sure you have the following installed on your machine:

Node.js (LTS version recommended)

npm (Usually installed with Node.js)

MongoDB (locally or use a cloud instance like MongoDB Atlas)

Backend Setup The backend of this app is built with Node.js and Express. The backend server connects to MongoDB to handle data storage and retrieval.

Step 1: Install Dependencies Navigate to the backend folder and install the necessary dependencies:

bash Copy cd backend npm install The backend depends on the following packages:

bcryptjs: To hash passwords securely

body-parser: To parse incoming request bodies

cors: To enable Cross-Origin Resource Sharing (CORS)

express: Web framework for Node.js

jsonwebtoken: To generate and verify JWT tokens for authentication

mongoose: ODM for MongoDB

multer: Middleware for handling multipart/form-data (file uploads)

path: To handle and transform file paths

run the command in terminal npm i bcryptjs body-parser cors express jsonwebtoken mongoose multer path

Step 2: Run the Backend Server To start the backend server, use the following command:

npx nodemon index.js The server will start running and listen for requests on the port specified in the index.js file (usually localhost:5000 or another port if configured).

Frontend Setup The frontend of this app is built with React.

Step 1: Install Dependencies Navigate to the frontend folder and install the necessary dependencies:

bash Copy cd frontend npm install Step 2: Run the Frontend App Once the dependencies are installed, you can run the development server for the React app:

bash Copy npm run dev This will start the React development server, and the app will be available at localhost:3000 by default.

Connecting Frontend and Backend Make sure that both the frontend and backend servers are running. The frontend will make API calls to the backend (usually at http://localhost:5000 or another configured API endpoint). You may need to adjust the API URLs in the frontend code to match the backend server URL.

CORS CORS should be enabled by default in the backend using the cors middleware. If you encounter CORS issues, ensure the following middleware is included in your index.js:

javascript Copy const cors = require('cors'); app.use(cors()); Environment Variables The backend may require some environment variables for database connection and JWT secret. You can create a .env file in the backend folder with the following values:

ini Copy MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret Make sure to replace your_mongodb_connection_string with your MongoDB connection URL (locally or from MongoDB Atlas) and your_jwt_secret with a strong secret key for JWT token generation.

Deployment Backend To deploy the backend, you can use platforms like Heroku, DigitalOcean, or AWS. Follow the respective platform's guide for deploying Node.js applications.

Frontend The frontend React app can be deployed to services like Netlify, Vercel, or GitHub Pages. These services have easy deployment processes for React applications.

Troubleshooting CORS Issues: Ensure that cors is properly configured in the backend.

Missing Dependencies: Run npm install in both the frontend and backend folders if you see missing package errors.

MongoDB Connection: Check the MongoDB URI in the .env file for any connection issues.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors