https://github.com/lai-kevin/forum-microservice
Designed to provide a scalable and containerized environment for deploying a microservice-based application resembling a Reddit-style forum. Users can register, log in, and perform various actions such as creating posts, commenting, and voting on posts.
https://github.com/lai-kevin/forum-microservice
api express-js javascript microservice nodejs
Last synced: about 2 months ago
JSON representation
Designed to provide a scalable and containerized environment for deploying a microservice-based application resembling a Reddit-style forum. Users can register, log in, and perform various actions such as creating posts, commenting, and voting on posts.
- Host: GitHub
- URL: https://github.com/lai-kevin/forum-microservice
- Owner: lai-kevin
- Created: 2024-01-05T16:45:09.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-17T23:28:27.000Z (11 months ago)
- Last Synced: 2025-01-31T10:16:14.927Z (4 months ago)
- Topics: api, express-js, javascript, microservice, nodejs
- Language: JavaScript
- Homepage:
- Size: 2.09 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Forum-Microservice
## Overview
Forum-Microservice is designed to provide a scalable and containerized environment for deploying a microservice-based application resembling a Reddit-style forum. The docker image is available on [DockerHub](https://hub.docker.com/r/kevinlaisoftware/forum). This image encapsulates the Node.js application responsible for handling forum-related functionalities, with seamless integration capabilities for MongoDB.
## Technologies Used:
- JavaScript
- Express.js
- Node.js
- MongoDB
- Docker
- Github Actions
- Jest
- Bcrypt
- Postman
## Features- **Users:** The Forum-Microservice supports user management and authentication. Users can register, log in, and perform various actions such as creating posts, commenting, and voting on posts. The microservice provides APIs for user-related operations, allowing developers to integrate user functionality into their applications easily.
- **Microservices Architecture:** Built to operate as a microservice, promoting modularization and scalability within a broader system.
- **MongoDB Integration:** Supports dynamic connection to a MongoDB instance through the `MONGODB_URI` environment variable.## Postman Documentation
The API documentation can be found [here](https://documenter.getpostman.com/view/30898740/2sA3XQiNWS).## Usage
To run the Docker container, set the required environment variables and port bindings:
```bash
docker run -e MONGODB_URI= -p 8080:3000 your-docker-username/forum-microservice
```
## Getting Started1. **Pull the Docker Image:**
```bash
docker pull your-docker-username/forum-microservice
2. **Run the Docker Container:**
```bash
docker run -e MONGODB_URI= -p 8080:3000 your-docker-username/forum-microservice3. **Initialize Database and Admin:**
Adjust this template as needed to create an admin user
```javascript
// Setup database with initial test data.
// Include an admin user.
// Script should take admin credentials as arguments as described in the requirements doc.
require('dotenv').config();
const Questions = require("./models/questions");
const Comment = require("./models/comment");
const Answers = require("./models/answers");
const User = require("./models/users");
const { default: mongoose } = require("mongoose");
const bcrypt = require("bcrypt");const admin_email = process.argv[2];
const admin_password = process.argv[3];
const admin_username = process.argv[4];const saltRounds = 12; // Default salt rounds 12
const salt = bcrypt.genSaltSync(saltRounds);
const admin_passwordHash = bcrypt.hashSync(admin_password, salt);const mongoUrl = process.env.MONGODB_URI;
console.log(process.env.MONGODB_URI)
mongoose.connect(mongoUrl, { useNewUrlParser: true, useUnifiedTopology: true });
const database = mongoose.connection;
database.on('error', console.error.bind(console, 'connection error:'));
database.once('open', async () => {
console.log("Connected to database");
try {
const admin = new User({
username: admin_username,
email: admin_email,
passwordHash: admin_passwordHash,
admin: true,
});
await admin.save();
console.log("Admin user created");
} catch (error) {
console.log(error);
}
database.close();
});
```