As part of Northcoder's Skills Bootcamp in Software Development, we were tasked with building a RESTful news API backend which can provide information to my other frontend project. This API will allow clients to access articles, grouped under topics, along with comments and the users behind them - akin to Reddit or similar news services.
This backend project follows the MVC pattern and was built in JavaScript using Express to enable easier server routing and error handling. PostgreSQL was used for the databases and Jest with SuperTest for TDD. Moreover, a CI/CD pipeline has been implemented through Github Actions to ensure tests pass before merging any pull requests.
My backend project along with the available endpoints can be found here (may take a minute to load initially):
https://nc-news-452q.onrender.com/api
The online database is hosted via ElephantSQL whereas the API is hosted via Render.
If you wish to run this backend project locally, ensure you fulfill the requirements below before following the instructions.
- Node.js (v20.11.0)
- PostgreSQL (v14.9)
- Navigate to the directory you wish to download the repository to
- Run the following commands inside the terminal:
git clone https://github.com/kapilamin/nc-news.git
- Navigate into the newly created
be-nc-news
directory - Run the following command to install all the needed dependencies:
npm install
- You may need to start your PostgreSQL server if it hasn't already
- Run the following command inside the terminal to create your local databases:
npm run setup-dbs
- Create the following 2 files inside the root directory:
.env.test
.env.development
- Add the following single line to each file:
PGDATABASE=<database_name>
- Replace
<database_name>
with the appropriate name (these can be found in the/db/setup.sql
file) - Run the following command inside the terminal to test everything has been set up correctly:
npm t
- If everything passes, you are free to play around as you wish 😊