This app is literally what the name suggests. Its an application which lets users create posts and comment on their or others' post. Deployed on https://post-comment-app.onrender.com
There are 2 ways to setup and run the application locally
- Using Nodejs
- Using Docker
Prerequisites:
- MongoDB Atlas account and a running cluster and its uri
- NodeJs (How to install NodeJS ?)
- Docker (How to install Docker ?)
Lets get started
-
Clone the repository and navigate to the root folder.
-
Create a
.env
file in root foldertouch .env
-
Enter the following details in the
.env
fileDB_URL = YOUR_MONGO_URL JWT_SECRET = YOUR_JSON_WEB_TOKEN_SECRET
eg.
DB_URL = mongodb://username:password@host:port/database JWT_SECRET = sdkasdklakwko12k3w1l32l2kdflksdklsjke
-
Open the terminal in the root folder and run the following commands :
npm i && node index
-
Once this is done, the server is up and runnning at port 8000
DB Connected Successfully Server is listening at port : 8000
-
To run the app with docker, run the following command
docker build --build-arg DB="mongodb://username:password@host:port/database" \ --build-arg JWTSEC="sdkasdklakwko12k3w1l32l2kdflksdklsjke" \ -t post-comment-app:latest .
-
To run the application, run
docker run -it --rm --name postcommentapp -p 8000:8000 post-comment-app:latest
-
The Server is up and running on localhost:8000
-
Backend - NodeJS
For backend nodejs seemed easy choice because of it developer-friendliness which allows for faster deployment of new features easily
-
Database - MongoDB
Mongo made sense here as it provides complete flexibility over schema (which is a neccessity at early stage) and facilitates faster & accessible development with help of its cloud clusters
-
Frontend - Static files served by ExpressJS
Using a framework like React/Angular made no sense for lightweight application like this, hence static files were an easy choice.
-
Users collection
Name string Email string Password string Image string -
Posts
Content string Author objectID (ref users) CreatedAt date Comments []ObjectID (ref comments) -
Comments
Text String Author (ref users) CreatedAt Date
- Users can view the posts without logging in but if they wish to post or comment something, they have to login.
- Users are logged in with a JWT cookie.
- Once they are done, they can logout and view again