Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 2.78 KB

README.md

File metadata and controls

84 lines (63 loc) · 2.78 KB

Northcoders News API

NodeJS Express.js codecov

A simple news API complete with topics, articles, users, comments, and some sample data to get started. Part of a backend project to learn more about building REST APIs using Express.js, interacting with postgres databases and CRUD operations, error handling, TDD, and best practices.

It's now live! 🚀

Try it out HERE for a preview

(As this is a 🔬small🔬 project, it's deployed on a free plan so the instance might spin down with inactivity every 15 mins. If your first request takes a few seconds, this is likely the reason why)

Some of the supported GET endpoints to try out:

  • GET /api
  • GET /api/topics
  • GET /api/articles (with optional query parameter topic, try ?topic=coding)
  • GET /api/articles/:article_id
  • GET /api/articles/:article_id/comments

For a full list of available endpoints and their detailed descriptions, check out endpoints.json, or /api

Setup and Testing

To run the development server and tests on your own device:

Important

Make sure you have node.js and npm installed and updated, and psql setup and running before proceeding.

This project was developed using node.js v20.5.0, npm 9.8.0, and psql 14.8

1. Clone the repo

  git clone https://github.com/Ak5cel/nc-news.git
  cd nc-news/

2. Install dependencies

  npm install

This will install all dependencies, including the devDependencies used for testing and seeding the development+test databases

3. Setup environment variables

Create two dotenv files .env.test and .env.development in the root directory as follows:

  # in .env.development
  PGDATABASE=nc_news
  # in .env.test
  PGDATABASE=nc_news_test

4. Create the databases and seed the development database

  npm run setup-dbs
  npm run seed

5. Test everything's working:

(The tests are setup to automatically re-seed the testing database before each test)

  # to run full test suite (using jest)
  npm test

  # (OR)
  #  to run just the tests for the api endpoints
  npm test app

6. Run the server locally (on port 9090 by default)

  npm run dev

All good! 🎉

Now open up a client (Insomnia, Postman, browser, or from your terminal using curl) and make a GET request to http://localhost:9090/api to get started.


💜