Follow these steps to get the project up and running on your machine:
-
Clone the repository:
Clone the project repository to your local machine using git.
git clone https://github.com/raj17ce/Twitter-Backend.git cd Twitter-Backend
-
Install dependencies:
Run the following command to install the required dependencies.
npm install
-
Create
.env
file:- Duplicate
.env.example
and rename it to.env
. - Update the
DatabaseURI
variable with the appropriate MongoDB URI. Make sure to append/dbname
at the end of the URI. - Update the
PORT
number to suit your requirements. - Set the
JWTSecretKey
to any secure string of your choice, but ensure it remains confidential and is not exposed.
- Duplicate
Note: You can run the project either locally or with Docker Compose, depending on your preference. Below is a guide for both methods, choose whichever suits your needs.
Make sure you have the following installed on your machine:
Node.js
(v12 or above)MongoDB Community Server
orAtlas
(Not needed if you run MongoDB on a Docker container)Docker
(for running MongoDB in a container, optional)
-
Run a MongoDB instance:
You can run MongoDB in one of the following ways:
-
Run MongoDB Community Server locally: Make sure MongoDB is installed and running on your machine.
-
Run MongoDB on MongoDB Atlas (Cloud): Set up a MongoDB Atlas instance and copy the connection URI.
-
Run MongoDB in a Docker Container: Use the following command to run MongoDB in a Docker container:
docker run --name mongodb-server -p 27017:27017 -d mongodb/mongodb-community-server:latest
-
-
Start the server:
You can run the server in development mode or production mode:
-
For development:
npm run dev
-
For production:
npm run start
-
Make sure you have the following installed on your machine:
Docker
(rundocker --version
to check)Docker-Compose
(rundocker-compose --version
to check)
-
Start the Server
Run the following command to run this multi container backend server using docker-compose.
docker-compose up
To ensure that the application and the MongoDB database are running smoothly, you can perform a health check by sending a GET request to the following endpoint:
GET http://localhost:8000/api/v1/health
Below is a sample success response. If you get this response, it means that the Server and Database is UP and Running.
{
"success": true,
"message": "Server and Database is Up and Running.",
"data": {
"status": "UP",
"services": {
"database": "connected"
}
},
"err": {}
}
-
User can Signup/Login.
-
User password is stored in encrypted form.
-
User can craete a Tweet.
-
Tweet can also include hashtags.
-
User can Like/UnLike a Tweet.
-
User can Comment on a Tweet as well as on a Comment.
-
User can Delete Tweets and Comments.