Backend for Blogging platform with authentication and features such as create, read, update and delete posts.
Setup the .env. Have kept the env variables for ease of testing. Update mongoDB uri to match the docker/normal setup requirement
To install the dependencies, run the following command:
npm install
To run the project in development environment (handles build automatically), use the following command:
npm run dev
To build the project, use the following command:
npm run build
To run the project, use the following command:
npm start
To run tests, use the following command:
npm run build
npm test
Install docker in your system. To run docker container, use the following command:
docker-compose up
Use Postman to trigger API calls.
- Call
POST /author/register
to create an author. - Call
POST /author/login
to login, which returns a token. - Use the token as a bearer token for creation, updation, and deletion.
POST /api/posts
for creating a blog post.PUT /api/posts/:id
for updating a blog post.DELETE /api/posts/:id
for deleting a blog post.
GET /api/posts
for getting all blog posts.page
andpageSize
can be passed as query params for pagination.GET /api/posts/:id
for getting a post by id.
API documentation with Postman
- Used Winston for logging error, infos and warnings to a file and to console
- Used Mongoose for defining schemas which helps with data validation and organization
- Used helmet to strengthen CSP to avoid XSS
- Used bcrypt to hash the password
- Used JWT authentication for protecting routes
- Used JOI for validation for providing a layer of protection over database validation.