The NC News API is designed to allow programmatic access to application data and is intended to mimic the functionality of real-world backend services like Reddit. Built using Node.js and Express.js, and interacting with a PostgreSQL (PSQL) database, this API allows users to retrieve articles, comments, topics, and user information. Additionally, it supports filtering, sorting, and updating article data, along with managing comments.
For API testing, SuperTest was used in conjunction with Jest. SuperTest, a robust testing library tailored for evaluating REST APIs built with frameworks like Express.js, seamlessly integrates with Jest to provide comprehensive testing capabilities.
You can find the hosted version of the NC News API Project here.
- GET /api/topics: Responds with an array of topics.
- GET /api: Responds with an array of available endpoints.
- GET /api/articles/:article_id: Responds with a single article by article_id.
- GET /api/articles: Responds with an array of articles.
- GET /api/articles/:article_id/comments: Responds with an array of comments by article_id.
- POST /api/articles/:article_id/comments: Adds a comment to an article by article_id.
- PATCH /api/articles/:article_id: Updates an article by article_id.
- DELETE /api/comments/:comment_id: Deletes a comment by comment_id.
- GET /api/users: Responds with an array of users.
- GET /api/articles (Queries): Allows articles to be filtered and sorted.
- GET /api/articles/:article_id (comment count): Adds a comment count to the response when retrieving a single article.
To get started with the Northcoders News API locally, follow these steps:
git clone https://github.com/AnnaTas77/nc-news-backend-project
npm install
In order to successfully connect to the two databases locally, please make sure to set the following environment variables:
- Create a new file in the root directory and name it ".env.development".
- In the ".env.development" file add the following line: "PGDATABASE=nc_news" and save the file.
- Create another new file in the root directory and name it ".env.test".
- In the ".env.test" file add the following line: "PGDATABASE=nc_news_test" and save the file.
- Add these two files as ".env.*" to the ".gitignore" file. Set up the local database:
npm run setup-dbs
npm run seed
npm test