Welcome to the Northcoders News API! This is a RESTful API designed to simulate a real-world backend service, similar to Reddit. It allows users to interact with articles, topics, and users, and includes full CRUD functionality for managing these resources.
You can access the live API here:
Northcoders News API - Live Version
This project provides endpoints to interact with the data on topics, articles, and users. It simulates a news platform where users can post articles, vote on them, and comment on topics.
- User management (create, update, delete)
- CRUD operations for articles
- Vote on articles and comments
- Comment on articles
Before running the project, please ensure you have the following installed:
- Node.js (>= 14.x) 🟢
- PostgreSQL 🛠️
- npm 📦
To get the API up and running, follow these steps:
Start by cloning the repository to your local machine:
git clone https://github.com/erascu/nc-news-api.gitNavigate to the project directory and install the required dependencies using npm:
cd nc-news-api
npm installThis project uses dotenv to securely manage the database connection. You need to create two environment files for different environments:
- .env.development for your local development environment.
- .env.test for testing purposes.
Steps to set up:
- Create the files in the root directory of the project.
- Add the following lines to each file:
-
.env.development:
PGDATABASE=nc_news
-
.env.test:
PGDATABASE=nc_news_testFor security reasons, the .env files are added to .gitignore to prevent sensitive information (like database credentials) from being uploaded to GitHub or any other public repositories. In a real-world application, you should never share your actual database connection details publicly. The .env files are local to your machine, and by gitignoring them, we ensure your credentials remain private.
Before seeding the database with initial data, you need to set up the database by creating and dropping the necessary tables. Run the following command to drop and create the tables:
npm run setup-dbsAfter setting up the database, you'll need to seed it with initial data. Use the following command to seed the database:
npm run seedTo ensure everything is working correctly, run the tests using:
npm testYou can interact with the following endpoints via the hosted version of the API:
- GET /api/topics - Get all topics
- GET /api/users - Get a list of all users
- GET /api/articles - Get all articles or filter them (optional query parameters: sort_by, order)
- GET /api/articles/:article_id - Get a single article by ID
- GET /api/articles/:article_id/comments - Retrieves all comments for a specific article by its article_id
- POST /api/articles/:article_id/comments - Creates a comment for the specified article
{
"username": "existing_author_username",
"body": "comment_content"
}
- PATCH /api/articles/:article_id - Update article votes
{
"inc_votes": newVote
}
- DELETE /api/articles/:article_id - Delete an article
- This project was developed to demonstrate full-stack REST API design using Node.js, Express, and PostgreSQL.
- The project is configured for easy deployment on platforms like Render, and it uses Supabase for database management.
This portfolio project was created as part of a Digital Skills Bootcamp in Software Engineering provided by Northcoders