Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💱 Currency Converter API

The Currency Converter API is a Node.js-based backend project that allows users to register, authenticate, and convert currencies in real time using live exchange rate data. This project is built with Express, MongoDB, and integrates a third-party currency conversion API. It also supports token-based authentication using JWT.


📌 Project Overview

This project simulates a real-world API for a currency converter app. It enables:

  • User account creation and login
  • Secure authentication using JWT
  • Currency conversion from one currency to another using live exchange rates
  • Modular, scalable folder structure following best practices

Ideal for anyone looking to understand:

  • RESTful API development
  • MongoDB with Mongoose
  • Third-party API integration
  • JWT authentication

✨ Features

  • User signup and login
  • Protected routes with JWT
  • Real-time currency conversion via external API
  • Clean folder structure using MVC pattern
  • Fully testable with Thunder Client/Postman
  • MongoDB persistence for user data

🛠️ Technologies Used

  • Node.js – JavaScript runtime
  • Express.js – API framework
  • MongoDB – NoSQL database
  • Mongoose – ODM for MongoDB
  • JWT – Token-based authentication
  • Axios – For calling external currency API
  • dotenv – Environment variable management
  • Nodemon – Development tool
  • Thunder Client – API testing (VS Code extension)

🚀 Setup Instructions

1. Clone the Repository

git clone https://github.com/vermaharsha/currency-converter-api.git
cd currency-converter-api

2. Install Dependencies

npm install

3. Create a .env File

Create a .env file in the root directory and add the following:

PORT=5000
MONGO_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<dbname>
JWT_SECRET=your_jwt_secret
CURRENCY_API_URL=https://v6.exchangerate-api.com/v6
CURRENCY_API_KEY=your_currency_api_key

Replace <username>, <password>, <cluster>, <dbname>, and API key with actual values.

4. Start the Server

npm run dev

Server will run at http://localhost:5000


📫 API Endpoints

All routes starting with /api are available for public or authenticated access.


1️⃣ Signup a New User

  • Method: POST
  • URL: /api/auth/signup
  • Body (JSON):
{
  "username": "harsha",
  "email": "harsha@example.com",
  "password": "securepass123"
}
  • Response:
{
  "message": "User registered successfully"
}

2️⃣ Login to Get JWT Token

  • Method: POST
  • URL: /api/auth/login
  • Body (JSON):
{
  "email": "harsha@example.com",
  "password": "securepass123"
}
  • Response:
{
  "token": "JWT_TOKEN",
  "user": {
    "id": "user_id",
    "username": "harsha",
    "email": "harsha@example.com"
  }
}

3️⃣ Convert Currency (Protected)

  • Method: GET
  • URL: /api/currency/convert?from=USD&to=INR&amount=100
  • Headers:
Authorization: Bearer <JWT_TOKEN>
  • Response:
{
  "from": "USD",
  "to": "INR",
  "amount": "100",
  "rate": 83.01,
  "convertedAmount": 8301
}

🖼️ Visuals (API Testing Screenshots)

🧾 1. Signup a New User

User Registration


🔑 2. Login to Get JWT Token

User Login


💱 3. Test Currency Conversion Endpoint

Test Currency Conversion Endpoint


🗂️ 4. MongoDB (User Collection View)

MongoDB Database


🙋‍♀️ Author

Made with ❤️ by Harsha Verma

About

A Node.js API for user auth and real-time currency conversion using live exchange rates

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages