A simple and modular REST API built with Node.js, Express, and MongoDB to handle:
- ✅ User registration and login
- 🔐 Authentication & JWT authorization
- 🧠 Password hashing with
bcryptjs - 🖼️ User-specific data: saved artworks (favourites)
- 📜 Search history tracking
- Node.js
- Express
- MongoDB (with Mongoose)
- bcryptjs – for password hashing
- jsonwebtoken – for issuing JWT tokens
- passport & passport-jwt – for authentication middleware
- dotenv – for managing environment variables
- CORS – for cross-origin support
git clone https://github.com/your-username/user-api.git
cd user-apinpm installCreate a .env file in the root directory with the following:
PORT=8080
JWT_SECRET=create_your_own_secret_key
MONGO_URL=your_mongo_url_here
node server.jsUse Postman or any HTTP client to test the API by making requests to the endpoints.
POST /api/user/register — Register a new user
POST /api/user/login — Login and receive a JWT<your_token>
Use the JWT to access protected routes like:
- GET /api/user/favourites
- PUT /api/user/favourites/:id
- DELETE /api/user/favourites/:id
- GET /api/user/history
- PUT /api/user/history/:id
- DELETE /api/user/history/:id
Include the JWT token in the Authorization header like this:
Authorization: jwt <your_token>
MIT License
Sonam Jamtsho
📧 sjjamtsho@gmail.com | 🔗 LinkedIn