NC News is a RESTful API that provides access to news articles, comments, users, and topics. It allows users to retrieve, filter, and interact with articles and comments. The project is built using Node.js, Express.js, and PostgreSQL.
You can access the hosted version of the API here:
👉 NC News API
Before setting up and running this project, ensure you have the following installed:
- Node.js (Minimum version: v18.0.0)
- PostgreSQL (Minimum version: v12.0)
- Git
First, clone the repository to your local machine and navigate into the project directory:
git clone https://github.com/PabloProgramming/news_backend
cd news_BE
Install all necessary dependencies:
npm install
Before running the project, you need to set up the PostgreSQL databases.
Run the following command to create both the development and test databases:
npm run setup-dbs
You must create two .env files in the root directory of the project:
📄 .env.development
PGDATABASE=nc_news
📄 .env.test
PGDATABASE=nc_news_test
🚨 Make sure your .gitignore
includes:
.env.*
This prevents sensitive credentials from being uploaded to GitHub.
After setting up the database, seed both the dev-db and the test-db:
npm run seed-test
npm run seed-dev
This command populates the database with sample articles, users, topics, and comments.
To ensure everything is set up correctly, run the test suite:
npm test
If everything is correct, all tests should pass successfully.
Start the development server with:
npm start
By default, the server will run on port 9090. You should see an output like:
Listening on port 9090...
You can then access the API at:
For a list of available endpoints and how to interact with the API, check out:
If you see this error when running the project, make sure:
- You have created the
.env
files (.env.development
and.env.test
). - You have run
npm run setup-dbs
to create the databases.
- Ensure PostgreSQL is running on your machine.
- Check that the database names in your
.env
files match the actual databases created.
- If deploying this project to a hosting service (e.g., Heroku, Render), set the
DATABASE_URL
environment variable accordingly. - The
NODE_ENV
variable is automatically set totest
when runningnpm test
.
If you'd like to contribute:
1️⃣ Fork the repository 🍴
2️⃣ Create a new branch 🛠️
3️⃣ Make your changes and commit them ✅
4️⃣ Submit a pull request 📩
Let's build something great together! 🚀✨
✅ Node.js: v16+
✅ PostgreSQL: v12+
This project is licensed under the MIT License.
💡 Need Help? Feel free to reach out or create an issue on GitHub! 😊
Happy coding! 🚀👨💻