This is a mock News Api that was made a a back-end project as part of the Northcoders Bootcamp. It can be found here.
For this project I learnt how to make use of Express, Postgres and Knex to create a funtional API with multiple endpoints listed below:
GET /api
GET /api/topics
GET /api/articles
GET /api/articles/:article_id
PATCH /api/articles/:article_id
GET /api/articles/:article_id/comments
POST /api/articles/:article_id/comments
GET /api/users/:username
PATCH /api/comments/:comment_id
DELETE /api/comments/:comment_id
While this is a funtional API my plans to add more endpoints are on hold until I complete the course after which I will hopefully have the time to add some more.
These will include:
GET /api/articles (with queries/pagination)
GET /api/articles/:article_id/comments(with queries/pagination)
DELETE /api/articles/:article_id
POST /api/topics
POST /api/users
GET /api/users
Node.js: v15.6.0
Postgres: v8.5.1
Fork my project the clone to your local machine e.g:
git clone https://github.com/DCrawley94/be-nc-news.git
Install all dependencies using a package manager e.g:
npm install
Additionally this project requires the creation of your own knexfile.js which should look like this:
const ENV = process.env.NODE_ENV || 'development';
const baseConfig = {
client: 'pg',
migrations: {
directory: './db/migrations',
},
seeds: {
directory: './db/seeds',
},
};
const customConfig = {
development: {
connection: {
database: 'nc_news',
username: '*YOUR PSQL USERNAME HERE*',
password: '*YOUR PSQL PASSWORD HERE*',
},
},
test: {
connection: {
database: 'nc_news_test',
username: '*YOUR PSQL USERNAME HERE*',
password: '*YOUR PSQL USERNAME HERE*',
},
},
};
module.exports = { ...customConfig[ENV], ...baseConfig };
More information on creating your version can be found here.
To seed the database simply run the seeding script using your package manager e.g:
npm run seed
There is a test suite written that tests all current endpoints and error handling as well as several utility functions used in the seeding process.
npm run test
👤 Duncan Crawley
- Github: @DCrawley94
- LinkedIn: @duncan-crawley
- My Portfolio: https://dcrawley94.github.io/