A full-stack web application for exchanging products and items. Users can list products they want to trade, browse available items by category, search for specific products, and connect with other users for exchanges.
- User Authentication: Secure registration, login, and logout functionality with bcrypt password hashing
- Product Management: Users can create, view, and manage product listings
- Category Browsing: Browse products organized by categories
- Advanced Search: Search for products using keywords and filters
- Image Upload: Upload product images with image processing using Sharp
- User Dashboard: Personal dashboard to manage posted products and account settings
- Admin Panel: Administrative dashboard for managing users and products
- Wishlist: Save favorite products for later viewing
- Role-Based Access: Different permissions for regular users and administrators
- Flash Messages: User-friendly feedback messages for actions
- Responsive Design: Mobile-friendly interface
- Node.js - Runtime environment
- Express.js - Web application framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- bcrypt - Password hashing
- express-session - Session management
- connect-mongo - MongoDB session store
- jsonwebtoken - JWT authentication
- cookie-parser - Cookie parsing middleware
- EJS - Templating engine
- express-ejs-layouts - Layout support for EJS
- Multer - File upload handling
- Sharp - Image processing and optimization
- dotenv - Environment variable management
- method-override - HTTP method override
- connect-flash - Flash message middleware
- cors - Cross-origin resource sharing
- nodemon - Development auto-restart (dev dependency)
Before running this application, make sure you have:
- Node.js (v14 or higher)
- MongoDB (local installation or MongoDB Atlas account)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/DStojanac/Web-app.git cd Web-app -
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory with the following variables:PORT=3000 MONGODB_URI=your_mongodb_connection_string SESSION_SECRET=your_session_secret_key JWT_SECRET=your_jwt_secret_key
-
Start the application
For production:
npm start
For development (with auto-restart):
npm run dev
-
Access the application
Open your browser and navigate to:
http://localhost:3000
Web-app/
├── middleware/ # Custom middleware functions
│ ├── checkAuth.js # Authentication middleware
│ └── isAdmin.js # Admin authorization middleware
├── public/ # Static files
│ ├── css/ # Stylesheets
│ ├── img/ # Images
│ ├── js/ # Client-side JavaScript
│ └── uploads/ # Uploaded product images
├── server/
│ ├── config/ # Configuration files
│ │ └── db.js # Database connection
│ ├── controllers/ # Route controllers
│ │ ├── adminController.js
│ │ ├── authController.js
│ │ ├── dashboardController.js
│ │ └── mainController.js
│ ├── models/ # Database models
│ │ ├── Product.js # Product schema
│ │ └── User.js # User schema
│ └── routes/ # Route definitions
│ ├── admin.js # Admin routes
│ ├── auth.js # Authentication routes
│ ├── dashboard.js # User dashboard routes
│ └── index.js # Public routes
├── views/ # EJS templates
│ ├── layouts/ # Layout templates
│ ├── partials/ # Reusable components (header, footer)
│ ├── admin/ # Admin views
│ └── users/ # User views
├── .env # Environment variables (create this)
├── package.json # Project dependencies
├── server.js # Application entry point
└── README.md # Project documentation
{
username: String (required, unique),
email: String (required, unique),
password: String (required, hashed),
role: String (enum: ['admin', 'user'], default: 'user'),
wishlist: [ObjectId] (references Product),
postedProducts: [ObjectId] (references Product)
}{
name: String (required),
description: String,
price: Number (required),
tradeFor: String (required),
category: String (required),
contactPhone: String (required),
email: String (required),
user: ObjectId (references User),
imageCover: String (required),
images: [String],
published: Boolean (default: false)
}Create a .env file with the following variables:
| Variable | Description | Example |
|---|---|---|
PORT |
Server port number | 3000 |
MONGODB_URI |
MongoDB connection string | mongodb://localhost:27017/webapp or mongodb+srv://... |
SESSION_SECRET |
Session encryption key | your_random_secret_key |
JWT_SECRET |
JWT token secret | your_jwt_secret_key |
This web application was created as a university project to demonstrate full-stack web development skills including user authentication, database management, file uploads, and RESTful API design.