This project is an API for accessing news data programmatically (topics, articles, comments etc.). The purpose of the API is to mimic the building of a real world backend service (such as Reddit) which should provide this data to a front end application.
An overview of each endpoint, including a description, example requests and responses can be found on the /api route.
A hosted version of the API can be found here:
https://news-api-get0.onrender.com/api
To run this API locally, you will require the following dependencies to be installed.
- Node.js - minimum version 18 is required. Go to here to install.
- PostgreSQL - minimum version 14.9 is required. Go to here to install.
Follow the steps below to install the API
- Clone the repository
git clone https://github.com/ccdu1010/news-api.git
- Install dependencies by running the following command from the news-api (root) directory
npm install
- Create the database and tables
npm setup-dbs
- Seed sample data
npm seed
- To allow the API to connect to the database, an environment variable must be set to determine which database to connect to. To do this, please add a file named
.env.development
to the root directory with the following content:
PGDATABASE = nc_news
- Run the API
npm start
The tests for the API use SuperTest. To run these tests a test database must be used. As part of the commands above, this test database should already be created and seeded with test data. For the tests to run, another environment file named .env.test
should be added to the root directory with the following content:
PGDATABASE = nc_news_test
Then to run the tests:
npm test