A REST api written in TypeScript using NodeJS and Express to be consumed by blogs with some social friendly features. This api has been written (mostly) using the TDD methodology.
This has been my side project to experiment with NodeJS and with the backend world in general. The Blog api is built using the repository and unit of work pattern. Also in order to adhere to the SOLID principles it uses InversifyJS in order to implement the dependency injection mechanism. By using the Blog api you will have full control. Of course that comes with more manual work
Features will be documented soon
- NodeJS (minimum version 18) must me installed
- MariaDB. Check out this guide to get started
- Clone this repo
- Create a
.envfile at the root of the project and copy the following with your own values(remember to remove also the brackets)
# DB CONFIGURATION
DB_HOST={database_host}
DB_USER={database_user}
DB_PASS={database_password}
DB_NAME={database_name}
secret={jwt_secret}
confirmEmailSecret={confirm_email_secret}
# SWAGGER CONTACT INFO
SWAGGER_CONTACT_NAME={contact_name}
SWAGGER_CONTACT_MAIL={contact_email}
# NODEMAILER MAIL OPTIONS
# for info on this go to https://nodemailer.com/smtp/
MAIL_HOST={mail_host}
MAIL_PORT={mail_port}
MAIL_SECURE={mail_secure}
MAIL_AUTH_USER={mail_auth_user}
MAIL_AUTH_PASS={mail_auth_pass}
MAIL_TLS_REJECTUNAUTHORIZED={mail_tls_reject_unauthorized}
# WHERE TO REDIRECT WHEN CONFIRMATION OF AN EMAIL FAILS
APPLICATION_ERROR_PAGE=http://localhost:3000/whoops
# SENDER OF THE CONFIRMATION OR RESET PASSWORD EMAIL
FROM_EMAIL='"KomicGR" <info@komic.gr>'
# THIS IS USED IN THE CONFIRMATION EMAIL
# SENT TO THE USER UPON REGISTRATION
BACKEND_URL={api_url}
# THIS IS USED IN THE RESET LINK THAT IS SENT
# TO A USER BY EMAIL
APPLICATION_URL={client_url}
# A SECRET FOR EXPRESS SESSION
EXPRESS_SESSION_SECRET={your_secret}
# OPTIONAL, IF THIS IS NOT PROVIDED
# IT WILL RUN ON PORT 3001
PORT={the_port_where_the_api_will_run}
- Run
npm installoryarnto install the dependencies - Run
npm run db-uporyarn run db-upto run the migrations for the database - Run
npm run devoryarn dev
The api should be running on http://localhost:3000 (if you haven't define a port in .env). You will be redirected to http://localhost:3000/api-docs/v1. You can also check the v2 by changing the url to http://localhost:3001/api-docs/v2. Version 2 is not being developed. It exists as a PoC
- Run
npm testoryarn test
Even though I have tried to built this api using TDD unfortunately this is not the case for the repositories. Hopefully tests will be added eventually 😞
- Run
npm buildoryarn build - Set the same environmental variables with the appropriate values in your server
- Deploy / copy the
buildfolder in your server - Install the dependencies with
npm installoryarn - Start the app with
node app.js
- You can build a docker image of the api using the
Dockerfile - Make sure you have docker installed
- Make sure to setup you env vars in
.env - From the root of the project run
docker build . -t blog-apito create the image with the tagblog-api - Run a container using that image by running
docker run --rm -p 81:3001 --name blogapi -t blog-api - Visit
localhost:81
Contributions will be accepted very soon. Thank you for your interest! ❤️
- I will be more than happy to help you. You can report an issue using the (issues page)[https://gitlab.com/kormic/komicGR/-/issues]. Please be polite and try to be as descriptive as you can
This section will be filled soon