A simple blog app that lets users create blog posts with images, edit them and delete them.
You can see the frontend code here: Frontend repository
MERN Stack:
- tensorflowJS (for toxicity detection in the blog post)
- aws-sdk (to interact with various AWS services)
- bcrypt (for password hashing)
- cors (helps in enabling CORS)
- dotenv (to load environment variables from a .env file into process.env)
- jsonwebtoken (for creating and verifying JSON Web Tokens (JWTs) for user authentication and authorization)
- mongoose (for interacting with MongoDB and helps in defining schemas, models, and performing database operations)
- multer (a middleware used for handling multipart/form-data)
- multer-s3 (an extension of Multer for uploading files to Amazon S3)
To run the BlogOn API project locally, follow these steps:
- Clone the repository to your local machine:
git clone https://github.com/shm-dsgn/blog-api.git
- Navigate to the project directory:
cd blog-api
- Create a
.env
file in the project directory. - Create the follwing variables in the
.env
file:
JWT_SECRET = <Any string of your choice>
DB_USER = <MondoDB Database username>
DB_PASSWORD = <MondoDB Database password>
AWS_ACCESS_KEY_ID = <AWS access key id of the user who has permissions of S3 >
AWS_SECRET_ACCESS_KEY = <AWS secret access key of the user who has permissions of S3 >
AWS_BUCKET_NAME = <S3 bucket name>
CAPTCHA_SECRET = <Google reCAPTCHA v2 secret key>
- Change the Mongoose connection string in
index.js
to your own MongoDB connection string.
mongoose.connect(
`mongodb+srv://${dbUser}:${dbPassword}@<example>.mongodb.net/...`
);
- In the project directory, you can run
npm install
to install the project dependencies.
npm install
To start the development backend server and view the BlogOn API, run the following command:
npm start
This will launch the application on a local development server, typically at http://localhost:3001.
- /auth routes for user authentication
- /login route for user login
- /register route for user registration
- /post routes for blog post CRUD operations
- / route for getting all blog posts
- /create route for creating a new blog post
- /:id route for getting a blog post by id
- /edit route for updating a blog post
- /delete/:id route for deleting a blog post by id