This is a backend server application for a basic social media platform built with Node.js, Express, MongoDB, and GraphQL.
The Social Media API provides basic functionalities for user registration, authentication, posting content, following/unfollowing users, and retrieving posts. It is built using Node.js and Express framework, with MongoDB as the database. GraphQL is integrated for querying user profiles and posts.
- User registration and authentication
- Posting content (text-based)
- Following and unfollowing other users
- Retrieving user posts and following users' posts
- GraphQL endpoint for querying user profiles and posts
-
Clone the repository:
git clone <repository-url>
-
Install dependencies:
npm install
-
Set up environment variables by creating a
.env
file and defining the following variables:- PORT=3000
- MONGODB_URI=
- JWT_SECRET=
-
Start the server:
npm start
POST /register
: Register a new userPOST /login
: Login an existing userGET /allusers
: Get all usersGET /user/posts/:userId
: Get posts for a specific user by userIDGET /following/posts/:userId
: Get posts including those posted by users the current user is followingPOST /follow
: Follow a userPOST /unfollow
: Unfollow a user
POST /post
: Create a new post
The GraphQL endpoint is available at /graphql
. You can use GraphiQL to explore the schema and execute queries.
Authentication is implemented using JSON Web Tokens (JWT). When a user registers or logs in, a JWT token is generated and sent back to the client. This token should be included in the authorization header for protected routes.
- express
- mongoose
- bcryptjs
- jsonwebtoken
- express-graphql (for GraphQL endpoint)
- dotenv (for environment variables)
- cors