Skip to content

jtstothard/nc_news

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NC-News-api

Welcome to the North Coders News api!

This api provides access to the NC-News psql database through the knex library and node.js express module. Testing is via the mocha suite with chai blocks and supertest for testing server functionality.

Getting Started

Prerequisites

To check if you have Node.js, npm, git and postgress installed, run these command in your terminal:

node -v
npm -v
git --version
postgres -V

If it any are not installed then follow the instuction on the respective links below to install:

Installing

Clone the repository to your local machine

git clone https://github.com/jstothard/nc_news

Open the project folder and install the required dependencies

npm install

You will also need to create a knexfile in the root of the project directory, to create this:

touch knexfile.js

Then copy the following code over to the file updating with your credentials where required

const ENV = process.env.NODE_ENV || "development";

const { DATABASE_URL } = process.env;

const baseConfig = {
  client: "pg",
  migrations: {
    directory: "./db/migrations"
  },
  seeds: {
    directory: "./db/seeds"
  }
};

const customConfigs = {
  development: {
    connection: {
      database: "nc_news"
      // username: "",
      // password: "",
    }
  },
  test: {
    connection: {
      database: "nc_news_test"
      // username: "",
      // password: "",
    }
  },
  production: { connection: `${DATABASE_URL}?ssl=true` }
};

module.exports = { ...baseConfig, ...customConfigs[ENV] };

Initialise the database:

npm run setup-dbs

Seed the database with development data:

npm run seed

The database can now be run

npm run dev

The development database is now accessible locally from port 9090. Visit http://localhost:9090/api to confirm it is running, it will output a JSON of the endpoints available like below:

{
  "endpoints": {
    "topics": {
      "address": "/api/topics",
      "methods": [
        "GET"
      ]
    },
    "aticles": {
      "address": "/api/articles",
      "methods": [
        "GET"
      ]
    },
    ...

Running the tests

To run the automated tests:

npm test

To test the utility file tests:

npm run utils-test

Deployment

This database is hosted on Heroku at this address:
https://nc-news-jstothard.herokuapp.com/api/

Built With

  • Express - The web framework used
  • npm - Dependency Management
  • knex - Used to interface between SQL and Javascript
  • PostgreSQL - The database system used
  • Node Postgress - Used to interface between SQL and Javascript
  • Mocha - Test suite used
  • Chai - Assertion library for testing
  • nodemon - Used to monitor development server
  • supertest - Used to test server

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc

nc_news

Available Scripts

Create development and test databases locally:

npm run setup-dbs

Create a new migration file:

npm run migrate-make <filename>

Run all migrations:

npm run migrate-latest

Rollback all migrations:

npm run migrate-rollback

Run tests:

npm test

Rollback, migrate -> latest, then start inserting data into the database:

npm run seed

Run the server with nodemon, for hot reload:

npm run dev

Run the server with node:

npm start

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published