Prerequisites
Before installing, ensure your system meets these requirements:Required Software
Node.js
MongoDB
npm
Comes with Node.jsVerify installation:
Git
For cloning the repositoryVerify installation:
TRON Network Access
You’ll need access to the TRON blockchain:- Development/Testing: TRON Nile Testnet (free)
- Production: TRON Mainnet
The Nile testnet is recommended for development. It provides free testnet TRX and mirrors mainnet functionality.
Installation Steps
Clone the Repository
Clone the Crypto Shop Backend repository:Alternatively, download and extract the ZIP file from your repository.
Install Dependencies
Install all required npm packages:This installs:
- Express - Web framework
- Mongoose - MongoDB ODM
- TronWeb - TRON blockchain integration
- Socket.io - Real-time notifications
- JWT - Authentication tokens
- bcryptjs - Password hashing
- And more (see
package.jsonfor complete list)
Installation typically takes 1-3 minutes depending on your internet connection.
Set Up MongoDB
Choose one of the following options:
- Local MongoDB
- MongoDB Atlas
Start MongoDB locally:macOS (Homebrew):Linux (systemd):Windows:Verify it’s running:
Configure Environment Variables
Create a Edit
.env file in the project root:.env with your configuration:.env
Generate Secure Secrets
Generate cryptographically secure secrets for JWT:Start the Server
Run the development server with auto-reload:Or start in production mode:You should see:
Configuration Reference
Environment Variables
Complete reference of all supported environment variables:| Variable | Required | Default | Description |
|---|---|---|---|
MONGODB_URI | Yes | - | MongoDB connection string |
NODE_ENV | No | development | Environment: development, production |
PORT | No | 3000 | Server port |
TRON_NETWORK | Yes | - | TRON RPC endpoint URL |
ACCESS_TOKEN_SECRET | Yes | - | JWT access token secret (min 32 chars) |
REFRESH_TOKEN_SECRET | Yes | - | JWT refresh token secret (min 32 chars) |
CLIENT_URL | Yes | - | Frontend URL for CORS |
MERCHANT_WALLET_ADDRESS | No | - | Fallback merchant wallet (optional) |
TRON Network Endpoints
Project Structure
Understand the codebase organization:Database Setup
The application automatically creates collections and indexes on first run. No manual database setup is required.Collections Created
- users - User accounts and wallets
- products - Product catalog
- orders - Purchase orders
- transactions - Blockchain transactions
- sessions - Active user sessions (if implemented)
Initial Admin Account
To create an admin account, manually register a user and update their role in MongoDB:Alternatively, implement a seed script or use the first registered user as admin.
Security Configuration
The backend includes several security features enabled by default:Built-in Security
- Helmet - Sets secure HTTP headers
- CORS - Configured cross-origin resource sharing
- Rate Limiting - Prevents abuse (100 requests per 15 minutes)
- HPP - HTTP Parameter Pollution protection
- HttpOnly Cookies - Secure token storage
- bcrypt - Password hashing with salt rounds
Production Checklist
Before deploying to production:Production Security Checklist
Production Security Checklist
- Set
NODE_ENV=production - Use strong, unique JWT secrets (min 32 chars)
- Enable HTTPS/SSL
- Configure proper CORS origins
- Use MongoDB Atlas with IP whitelist
- Set up monitoring and logging
- Enable rate limiting (already configured)
- Use environment-specific TRON endpoints
- Set secure cookie settings
- Review and update
.envvariables
Troubleshooting
MongoDB Connection Failed
MongoDB Connection Failed
Error:
MongoServerError: Authentication failedSolutions:- Verify MongoDB is running:
mongosh - Check
MONGODB_URIin.env - For Atlas: verify IP whitelist and credentials
- Ensure database user has proper permissions
Port Already in Use
Port Already in Use
Error:
EADDRINUSE: address already in use :::3000Solutions:- Change
PORTin.envto a different value - Kill the process using port 3000:
TRON Network Connection Issues
TRON Network Connection Issues
Error: Connection to TRON network failedSolutions:
- Verify
TRON_NETWORKURL in.env - Test endpoint:
- Check your internet connection
- Try alternative endpoints (see Configuration Reference)
JWT Secret Too Short
JWT Secret Too Short
Error: JWT secret must be at least 32 charactersSolution:
Generate proper secrets:Update
.env with the generated values.Module Not Found Errors
Module Not Found Errors
Error:
Cannot find module 'express'Solution:
Reinstall dependencies:Verify Installation
Run through this checklist to ensure everything is properly installed:Next Steps
Quickstart Guide
Follow the quickstart to make your first API calls
API Reference
Explore all available endpoints
Authentication
Learn about JWT and role-based access
Deployment
Deploy to production