Create a secrets directory and Add the following files with the appropriate values
db_uri_dev.token: MongoDB URI for development
db_uri_prod.token: MongoDB URI for production
id_rsa_priv: Private key for JWT
id_rsa_pub: Public key for JWT
Run docker-compose to start the service
To start the service in development mode:
docker-compose -f docker-compose-dev.yml up
To start the service in production mode:
docker-compose -f docker-compose-prod.yml up
Option 2: Run Locally
Clone the repository
git clone git@github.com:ahmeducf/blog-api.git
Navigate to the project directory
cd blog-api
Install dependencies
npm install
Generate public and private keys for JWT
node generate_keypair.js <path-to-parent-directory># e.g. ./secrets
Populate the database with some sample data
node populate_db.js <your-mongodb-uri>
Create a .env file in the root directory and add the following environment variables
NODE_ENV=<development | production>
DB_URI_FILE=<path-to-db-uri-file># e.g. ./secrets/db_uri_dev.token
JWT_PRIVATE_KEY_FILE=<path-to-private-key-file># e.g. ./secrets/id_rsa_priv
JWT_PUBLIC_KEY_FILE=<path-to-public-key-file># e.g. ./secrets/id_rsa_pub
TEST_USERNAME=<your-test-username>
TEST_PASSWORD=<your-test-password>
Run the tests
npm test
Start the server
In development mode:
npm run dev
In production mode:
npm start
If I have time
Create a blog frontend to consume the API.
Create an admin dashboard frontend to manage the blog.
Support comments on posts.
Create Swagger documentation for the API.
Use Nginx as a reverse proxy server.
Use Redis for caching.
Use a CI/CD tool to automate the deployment process.